2017-11-06 19:22:02 +08:00
< script >
export default {
data() {
return {
activeName: 'second',
activeName2: 'first',
editableTabsValue: '2',
editableTabsValue2: '2',
editableTabs: [{
title: 'Tab 1',
name: '1',
content: 'Tab 1 content'
}, {
title: 'Tab 2',
name: '2',
content: 'Tab 2 content'
}],
editableTabs2: [{
title: 'Tab 1',
name: '1',
content: 'Tab 1 content'
}, {
title: 'Tab 2',
name: '2',
content: 'Tab 2 content'
}],
tabIndex: 2,
tabPosition: 'top'
}
},
methods: {
handleClick(tab, event) {
console.log(tab, event);
},
handleTabsEdit(targetName, action) {
if (action === 'add') {
let newTabName = ++this.tabIndex + '';
this.editableTabs.push({
title: 'New Tab',
name: newTabName,
content: 'New Tab content'
});
this.editableTabsValue = newTabName;
}
if (action === 'remove') {
let tabs = this.editableTabs;
let activeName = this.editableTabsValue;
if (activeName === targetName) {
tabs.forEach((tab, index) => {
if (tab.name === targetName) {
let nextTab = tabs[index + 1] || tabs[index - 1];
if (nextTab) {
activeName = nextTab.name;
}
}
});
}
this.editableTabsValue = activeName;
this.editableTabs = tabs.filter(tab => tab.name !== targetName);
}
},
addTab(targetName) {
let newTabName = ++this.tabIndex + '';
this.editableTabs2.push({
title: 'New Tab',
name: newTabName,
content: 'New Tab content'
});
this.editableTabsValue2 = newTabName;
},
removeTab(targetName) {
let tabs = this.editableTabs2;
let activeName = this.editableTabsValue2;
if (activeName === targetName) {
tabs.forEach((tab, index) => {
if (tab.name === targetName) {
let nextTab = tabs[index + 1] || tabs[index - 1];
if (nextTab) {
activeName = nextTab.name;
}
}
});
}
this.editableTabsValue2 = activeName;
this.editableTabs2 = tabs.filter(tab => tab.name !== targetName);
}
}
}
< / script >
2017-11-15 06:38:17 +08:00
## Tabulación
2017-11-06 19:22:02 +08:00
2017-12-03 18:03:06 +08:00
Divide colecciones de datos que están relacionados pero pertenecen a diferentes tipos.
2017-11-06 19:22:02 +08:00
2017-11-15 06:38:17 +08:00
### Uso básico
2017-11-06 19:22:02 +08:00
2017-11-15 06:38:17 +08:00
Tabulación básica y concisa
2017-11-06 19:22:02 +08:00
2017-12-03 18:03:06 +08:00
:::demo Tabulación provee funcionalidad de tarjeta selectiva. Por defecto, la primer pestaña es seleccionada como activa, y es posible activar cualquier pestaña estableciendo el atributo de `value` .
2017-11-06 19:22:02 +08:00
```html
< template >
< el-tabs v-model = "activeName" @tab -click = "handleClick" >
< 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 >
< / template >
< script >
export default {
data() {
return {
activeName: 'first'
};
},
methods: {
handleClick(tab, event) {
console.log(tab, event);
}
}
};
< / script >
```
:::
2017-11-15 06:38:17 +08:00
### Estilo de Tarjeta
2017-11-06 19:22:02 +08:00
2017-11-15 06:38:17 +08:00
Pestañas diseñadas como tarjetas.
2017-11-06 19:22:02 +08:00
2017-11-15 06:38:17 +08:00
:::demo Establecer `type` a `card` para obtener una pestaña diseñada como tarjeta.
2017-11-06 19:22:02 +08:00
```html
< template >
< el-tabs type = "card" @tab -click = "handleClick" >
< 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 >
< / el-tabs >
< / template >
< script >
export default {
data() {
return {
activeName: 'first'
};
},
methods: {
handleClick(tab, event) {
console.log(tab, event);
}
}
};
< / script >
```
:::
2017-11-15 06:38:17 +08:00
### Tarjeta con Bordes
2017-11-06 19:22:02 +08:00
2017-11-15 06:38:17 +08:00
Pestañas de tarjeta con bordes.
2017-11-06 19:22:02 +08:00
2017-11-15 06:38:17 +08:00
:::demo Establecer `type` a `border-card` .
2017-11-06 19:22:02 +08:00
```html
< el-tabs type = "border-card" >
< 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 >
< / el-tabs >
```
:::
2017-11-15 06:38:17 +08:00
### Posición de tabulación
2017-11-06 19:22:02 +08:00
2017-11-15 06:38:17 +08:00
Es posible usar el atributo `tab-position` para establecer la posición de la tabulación.
2017-11-06 19:22:02 +08:00
2017-11-15 06:38:17 +08:00
:::demo Es posible escoger entre cuatro direcciones: `tabPosition="left|right|top|bottom"`
2017-11-06 19:22:02 +08:00
```html
< template >
< el-radio-group v-model = "tabPosition" style = "margin-bottom: 30px;" >
< el-radio-button label = "top" > top< / el-radio-button >
< el-radio-button label = "right" > right< / el-radio-button >
< el-radio-button label = "bottom" > bottom< / el-radio-button >
< el-radio-button label = "left" > left< / el-radio-button >
< / el-radio-group >
< el-tabs :tab-position = "tabPosition" style = "height: 200px;" >
< 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 >
< / el-tabs >
< / template >
< script >
export default {
data() {
return {
tabPosition: 'top'
};
}
};
< / script >
```
:::
2017-11-15 06:38:17 +08:00
### Pestaña Personalizada
2017-11-06 19:22:02 +08:00
2017-12-03 18:03:06 +08:00
Es posible usar slots con nombre para personalizar el contenido de la etiqueta de la pestaña.
2017-11-06 19:22:02 +08:00
:::demo
```html
< el-tabs type = "border-card" >
< el-tab-pane >
< span slot = "label" > < i class = "el-icon-date" > < / i > Route< / span >
Route
< / 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 >
< / el-tabs >
```
:::
2017-11-15 06:38:17 +08:00
### Agregar y cerrar pestaña
2017-11-06 19:22:02 +08:00
2017-11-15 06:38:17 +08:00
Solo las pestañas de tipo tarjeta soportan adición y cierre.
2017-11-06 19:22:02 +08:00
:::demo
```html
< el-tabs v-model = "editableTabsValue" type = "card" editable @edit = "handleTabsEdit" >
< el-tab-pane
v-for="(item, index) in editableTabs"
:key="item.name"
:label="item.title"
:name="item.name"
>
{{item.content}}
< / el-tab-pane >
< / el-tabs >
< script >
export default {
data() {
return {
editableTabsValue: '2',
editableTabs: [{
title: 'Tab 1',
name: '1',
content: 'Tab 1 content'
}, {
title: 'Tab 2',
name: '2',
content: 'Tab 2 content'
}],
tabIndex: 2
}
},
methods: {
handleTabsEdit(targetName, action) {
if (action === 'add') {
let newTabName = ++this.tabIndex + '';
this.editableTabs.push({
title: 'New Tab',
name: newTabName,
content: 'New Tab content'
});
this.editableTabsValue = newTabName;
}
if (action === 'remove') {
let tabs = this.editableTabs;
let activeName = this.editableTabsValue;
if (activeName === targetName) {
tabs.forEach((tab, index) => {
if (tab.name === targetName) {
let nextTab = tabs[index + 1] || tabs[index - 1];
if (nextTab) {
activeName = nextTab.name;
}
}
});
}
this.editableTabsValue = activeName;
this.editableTabs = tabs.filter(tab => tab.name !== targetName);
}
}
}
}
< / script >
```
:::
2017-11-15 06:38:17 +08:00
### Botón disparador personalizado de la nueva pestaña
2017-11-06 19:22:02 +08:00
:::demo
```html
< div style = "margin-bottom: 20px;" >
< el-button
size="small"
@click ="addTab(editableTabsValue2)"
>
add tab
< / el-button >
< / div >
< el-tabs v-model = "editableTabsValue2" type = "card" closable @tab -remove = "removeTab" >
< el-tab-pane
v-for="(item, index) in editableTabs2"
:key="item.name"
:label="item.title"
:name="item.name"
>
{{item.content}}
< / el-tab-pane >
< / el-tabs >
< script >
export default {
data() {
return {
editableTabsValue2: '2',
editableTabs2: [{
title: 'Tab 1',
name: '1',
content: 'Tab 1 content'
}, {
title: 'Tab 2',
name: '2',
content: 'Tab 2 content'
}],
tabIndex: 2
}
},
methods: {
addTab(targetName) {
let newTabName = ++this.tabIndex + '';
this.editableTabs2.push({
title: 'New Tab',
name: newTabName,
content: 'New Tab content'
});
this.editableTabsValue2 = newTabName;
},
removeTab(targetName) {
let tabs = this.editableTabs2;
let activeName = this.editableTabsValue2;
if (activeName === targetName) {
tabs.forEach((tab, index) => {
if (tab.name === targetName) {
let nextTab = tabs[index + 1] || tabs[index - 1];
if (nextTab) {
activeName = nextTab.name;
}
}
});
}
this.editableTabsValue2 = activeName;
this.editableTabs2 = tabs.filter(tab => tab.name !== targetName);
}
}
}
< / script >
```
:::
2017-11-15 06:38:17 +08:00
### Atributos de Pestañas
2017-12-03 18:03:06 +08:00
| Atributo | Descripción | Tipo | Valores aceptados | Por defecto |
| ------------ | ------------------------------------ | ------- | --------------------- | --------------------------- |
| type | tipo de Pestaña | string | card/border-card | — |
| closable | si la Pestaña es cerrable | boolean | — | false |
| addable | si la Pestaña es añadible | boolean | — | false |
| editable | si la Pestaña es añadible y cerrable | boolean | — | false |
| value | nombre de la pestaña seleccionada | string | — | nombre de la primer pestaña |
| tab-position | posición de tabulación | string | top/right/bottom/left | top |
2017-11-06 19:22:02 +08:00
2017-11-15 06:38:17 +08:00
### Eventos de Pestañas
2017-12-03 18:03:06 +08:00
| Nombre de Evento | Descripción | Parámetros |
| ---------------- | ---------------------------------------- | ----------------------------- |
| tab-click | se lanza cuando se hace click a una pestaña | pestaña clickeada |
| tab-remove | se lanza cuando se hace click al botón tab-remove | nombre de la pestaña removida |
| tab-add | se lanza cuando se hace click al botón tab-add | — |
| edit | se lanza cuando los botones de tab-add y/o tab-remove son clickeados | (targetName, action) |
2017-11-06 19:22:02 +08:00
2017-11-15 06:38:17 +08:00
### Attributos del Tab-pane
2017-12-03 18:03:06 +08:00
| Atributo | Descripción | Tipo | Valores Aceptados | Default |
| -------- | ---------------------------------------- | ------- | ----------------- | ---------------------------------------- |
| label | título de la pestaña | string | — | — |
| disabled | si la Tabulación está deshabilitada | boolean | — | false |
| name | identificador correspondiente al activeName de la Tabulación, representando el alias del tab-pane | string | — | número ordinal del tab-pane en la secuencia, p.ej el primer tab-pane de pestañas es '1' |
| closable | si el Tab es cerrable | boolean | — | false |