element/examples/docs/en-US/tabs.md

155 lines
4.4 KiB
Markdown
Raw Normal View History

2016-11-13 03:58:45 +00:00
<script>
export default {
data() {
return {
activeName: 'first',
tabs: [
{label: 'User', content: '', name: 'first'},
{label: 'Config', content: '', name: 'second'},
{label: 'Role', content: '', name: 'third'},
{label: 'Task', content: '', name: 'last'}
]
}
},
methods: {
handleRemove(tab) {
console.log(tab);
},
handleClick(tab, event) {
console.log(tab, event);
}
}
}
</script>
## Tabs
2016-11-13 03:58:45 +00:00
Divide data collections which are related yet belong to different types.
2016-11-13 03:58:45 +00:00
### Basic usage
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.
```html
<template>
2016-11-13 03:58:45 +00:00
<el-tabs :active-name="activeName">
<el-tab-pane v-for="tab in tabs" :label="tab.label" :name="tab.name">{{tab.content}}</el-tab-pane>
</el-tabs>
</template>
<script>
export default {
data() {
return {
2016-11-13 03:58:45 +00:00
activeName: 'first',
tabs: [
{label: 'User', content: '', name: 'first'},
{label: 'Config', content: '', name: 'second'},
{label: 'Role', content: '', name: 'third'},
{label: 'Task', content: '', name: 'last'}
]
};
}
};
</script>
```
:::
### Card Style
2016-11-13 03:58:45 +00:00
Tabs styled as cards.
2016-11-13 03:58:45 +00:00
:::demo Set `type` to `card` can get a card-styled tab.
```html
<template>
<el-tabs type="card" @tab-click="handleClick" @tab-remove="handleRemove">
2016-11-13 03:58:45 +00:00
<el-tab-pane label="User"></el-tab-pane>
<el-tab-pane label="Config"></el-tab-pane>
<el-tab-pane label="Role"></el-tab-pane>
<el-tab-pane label="Task"></el-tab-pane>
</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);
}
}
};
</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`.
```html
<template>
<el-tabs type="card" :closable="true" @tab-click="handleClick" @tab-remove="handleRemove">
2016-11-13 03:58:45 +00:00
<el-tab-pane label="User"></el-tab-pane>
<el-tab-pane label="Config"></el-tab-pane>
<el-tab-pane label="Role"></el-tab-pane>
<el-tab-pane label="Task"></el-tab-pane>
</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);
}
}
};
</script>
```
:::
### Border card
Border card tabs.
:::demo Set `type` to `border-card`.
```html
<el-tabs type="border-card">
2016-11-13 03:58:45 +00:00
<el-tab-pane label="User"></el-tab-pane>
<el-tab-pane label="Config"></el-tab-pane>
<el-tab-pane label="Role"></el-tab-pane>
<el-tab-pane label="Task"></el-tab-pane>
</el-tabs>
```
:::
### Tabs Attributes
2016-11-13 03:58:45 +00:00
| Attribute | Description | Type | Accepted Values | Default |
|---------- |-------- |---------- |------------- |-------- |
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 |
### Tabs Events
2016-11-13 03:58:45 +00:00
| Event Name | Description | Parameters |
|---------- |-------- |---------- |
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 |
### Tab-pane Attributes
2016-11-13 03:58:45 +00:00
| Attribute | Description | Type | Accepted Values | Default |
|---------- |-------- |---------- |------------- |-------- |
2016-11-13 03:58:45 +00:00
| label | title of the tab | string | — | — |
| 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' |