2018-03-22 14:17:35 +00:00
|
|
|
<cn>
|
|
|
|
#### 自定义新增页签触发器
|
|
|
|
隐藏默认的页签增加图标,给自定义触发器绑定事件。
|
|
|
|
</cn>
|
|
|
|
|
|
|
|
<us>
|
|
|
|
#### Customized trigger of new tab
|
|
|
|
Hide default plus icon, and bind event for customized trigger.
|
|
|
|
</us>
|
|
|
|
|
|
|
|
```html
|
2017-12-01 10:48:16 +00:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<div :style="{ marginBottom: '16px' }">
|
2018-01-23 10:55:39 +00:00
|
|
|
<a-button @click="add">ADD</a-button>
|
2017-12-01 10:48:16 +00:00
|
|
|
</div>
|
2018-03-22 14:17:35 +00:00
|
|
|
<a-tabs
|
2017-12-01 10:48:16 +00:00
|
|
|
hideAdd
|
|
|
|
v-model="activeKey"
|
|
|
|
type="editable-card"
|
|
|
|
@edit="onEdit"
|
|
|
|
>
|
2018-03-22 14:17:35 +00:00
|
|
|
<a-tab-pane v-for="pane in panes" :tab="pane.title" :key="pane.key" :closable="pane.closable">
|
2017-12-01 10:48:16 +00:00
|
|
|
{{pane.content}}
|
2018-03-22 14:17:35 +00:00
|
|
|
</a-tab-pane>
|
|
|
|
</a-tabs>
|
2017-12-07 07:11:12 +00:00
|
|
|
</div>
|
2017-12-01 10:48:16 +00:00
|
|
|
|
|
|
|
</template>
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data () {
|
|
|
|
const panes = [
|
|
|
|
{ title: 'Tab 1', content: 'Content of Tab 1', key: '1' },
|
|
|
|
{ title: 'Tab 2', content: 'Content of Tab 2', key: '2' },
|
|
|
|
]
|
|
|
|
return {
|
|
|
|
activeKey: panes[0].key,
|
|
|
|
panes,
|
|
|
|
newTabIndex: 0,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
callback (key) {
|
|
|
|
console.log(key)
|
|
|
|
},
|
|
|
|
onEdit (targetKey, action) {
|
|
|
|
this[action](targetKey)
|
|
|
|
},
|
|
|
|
add () {
|
|
|
|
const panes = this.panes
|
|
|
|
const activeKey = `newTab${this.newTabIndex++}`
|
2018-09-05 13:28:54 +00:00
|
|
|
panes.push({ title: `New Tab ${activeKey}`, content: `Content of new Tab ${activeKey}`, key: activeKey })
|
2017-12-01 10:48:16 +00:00
|
|
|
this.panes = panes
|
|
|
|
this.activeKey = activeKey
|
|
|
|
},
|
|
|
|
remove (targetKey) {
|
|
|
|
let activeKey = this.activeKey
|
|
|
|
let lastIndex
|
|
|
|
this.panes.forEach((pane, i) => {
|
|
|
|
if (pane.key === targetKey) {
|
|
|
|
lastIndex = i - 1
|
|
|
|
}
|
|
|
|
})
|
|
|
|
const panes = this.panes.filter(pane => pane.key !== targetKey)
|
2019-04-17 01:21:35 +00:00
|
|
|
if (panes.length && activeKey === targetKey) {
|
|
|
|
if (lastIndex >= 0) {
|
|
|
|
activeKey = panes[lastIndex].key;
|
|
|
|
} else {
|
|
|
|
activeKey = panes[0].key;
|
|
|
|
}
|
2017-12-01 10:48:16 +00:00
|
|
|
}
|
|
|
|
this.panes = panes
|
|
|
|
this.activeKey = activeKey
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|
2018-09-05 13:28:54 +00:00
|
|
|
```
|