2016-11-13 03:58:45 +00:00
< script >
export default {
data() {
return {
2016-11-16 08:14:48 +00:00
activeName: 'first'
2016-11-13 03:58:45 +00:00
}
},
methods: {
handleRemove(tab) {
console.log(tab);
},
handleClick(tab, event) {
console.log(tab, event);
}
}
}
< / script >
2016-11-10 13:46:55 +00:00
## Tabs
2016-11-13 03:58:45 +00:00
Divide data collections which are related yet belong to different types.
2016-11-10 13:46:55 +00:00
2016-11-13 03:58:45 +00:00
### Basic usage
2016-11-10 13:46:55 +00:00
Basic and concise tabs.
2016-11-13 03:58:45 +00:00
:::demo Tabs provide a selective card functionality and it can be achieved by just using `el-tabs` and child element `el-tab-pane` . In these two elements, we provide a list of attributes. The `label` in `el-tab-pane` determines the label of selective cards, and you can write content in the label. In this example, we add a `active-name` attribute indicating the active card in `el-tabs` , which can take a `String` value. In the `el-tab-pane` you can set corresponding `name` attribute, and if there is no `name` , the default sequence is `1` /`2`/`3`/`4`. In this example, the selected card is card 2. If `name` is omitted, setting `active-name` to `2` can reach the same goal.
2016-11-10 13:46:55 +00:00
```html
< template >
2016-11-13 03:58:45 +00:00
< el-tabs :active-name = "activeName" >
2016-11-16 08:14:48 +00:00
< el-tab-pane label = "User" name = "first" > User< / el-tab-pane >
< el-tab-pane label = "Config" name = "second" > Config< / el-tab-pane >
< el-tab-pane label = "Role" name = "third" > Role< / el-tab-pane >
< el-tab-pane label = "Task" name = "fourth" > Task< / el-tab-pane >
< / el-tabs >
2016-11-10 13:46:55 +00:00
< / template >
< script >
export default {
data() {
return {
2016-11-16 08:14:48 +00:00
activeName: 'first'
2016-11-10 13:46:55 +00:00
};
}
};
< / script >
```
:::
### Card Style
2016-11-13 03:58:45 +00:00
Tabs styled as cards.
2016-11-10 13:46:55 +00:00
2016-11-13 03:58:45 +00:00
:::demo Set `type` to `card` can get a card-styled tab.
2016-11-10 13:46:55 +00:00
```html
< template >
< el-tabs type = "card" @tab -click = "handleClick" @tab -remove = "handleRemove" >
2016-11-16 08:14:48 +00:00
< el-tab-pane label = "User" > User< / el-tab-pane >
< el-tab-pane label = "Config" > Config< / el-tab-pane >
< el-tab-pane label = "Role" > Role< / el-tab-pane >
< el-tab-pane label = "Task" > Task< / el-tab-pane >
2016-11-10 13:46:55 +00:00
< / el-tabs >
< / template >
< script >
export default {
methods: {
handleRemove(tab) {
console.log(tab);
},
2016-11-13 03:58:45 +00:00
handleClick(tab, event) {
console.log(tab, event);
2016-11-10 13:46:55 +00:00
}
}
};
< / script >
```
:::
### Closable
Closable tabs.
2016-11-13 03:58:45 +00:00
:::demo You can set `closable` attribute in `el-tabs` . It accept `Boolean` and Tab will be closable when the boolean is `true` .
2016-11-10 13:46:55 +00:00
```html
< template >
< el-tabs type = "card" :closable = "true" @tab -click = "handleClick" @tab -remove = "handleRemove" >
2016-11-16 08:14:48 +00:00
< el-tab-pane label = "User" > User< / el-tab-pane >
< el-tab-pane label = "Config" > Config< / el-tab-pane >
< el-tab-pane label = "Role" > Role< / el-tab-pane >
< el-tab-pane label = "Task" > Task< / el-tab-pane >
2016-11-10 13:46:55 +00:00
< / el-tabs >
< / template >
< script >
export default {
methods: {
handleRemove(tab) {
console.log(tab);
},
2016-11-13 03:58:45 +00:00
handleClick(tab, event) {
console.log(tab, event);
2016-11-10 13:46:55 +00:00
}
}
};
< / script >
```
:::
### Border card
Border card tabs.
:::demo Set `type` to `border-card` .
```html
< el-tabs type = "border-card" >
2016-11-16 08:14:48 +00:00
< el-tab-pane label = "User" > User< / el-tab-pane >
< el-tab-pane label = "Config" > Config< / el-tab-pane >
< el-tab-pane label = "Role" > Role< / el-tab-pane >
< el-tab-pane label = "Task" > Task< / el-tab-pane >
2016-11-10 13:46:55 +00:00
< / el-tabs >
```
:::
### Tabs Attributes
2016-11-13 03:58:45 +00:00
| Attribute | Description | Type | Accepted Values | Default |
2016-11-10 13:46:55 +00:00
|---------- |-------- |---------- |------------- |-------- |
2016-11-13 03:58:45 +00:00
| type | type of Tab | string | card/border-card | — |
| closable | whether Tab is closable | boolean | — | false |
| active-name | name of the selected tab | string | — | name of first tab |
2016-11-10 13:46:55 +00:00
### Tabs Events
2016-11-13 03:58:45 +00:00
| Event Name | Description | Parameters |
2016-11-10 13:46:55 +00:00
|---------- |-------- |---------- |
2016-11-13 03:58:45 +00:00
| tab-click | triggers when a tab is clicked | clicked tab |
| tab-remove | triggers when a tab is removed | removed tab |
2016-11-10 13:46:55 +00:00
### Tab-pane Attributes
2016-11-13 03:58:45 +00:00
| Attribute | Description | Type | Accepted Values | Default |
2016-11-10 13:46:55 +00:00
|---------- |-------- |---------- |------------- |-------- |
2016-11-13 03:58:45 +00:00
| label | title of the tab | string | — | — |
2016-11-18 07:41:08 +00:00
| label-content | render function for tab title | Function(h) | - | - |
2016-12-08 02:47:16 +00:00
| disabled | whether Tab is disabled | boolean | - | false |
2016-11-13 03:58:45 +00:00
| name | identifier corresponding to the activeName of Tabs, representing the alias of the tab-pane | string | — | ordinal number of the tab-pane in the sequence, i.e. the first tab-pane is '1' |