mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-15 09:50:58 +08:00
0636e1e240
* style: add import lint * chore: apply eslint rules * chore: add stricter lint * chore: lint all files * auto fix * manually fix * restore build-indices.ts
73 lines
1.6 KiB
Vue
73 lines
1.6 KiB
Vue
<template>
|
|
<div style="margin-bottom: 20px">
|
|
<el-button size="small" @click="addTab(editableTabsValue)">
|
|
add tab
|
|
</el-button>
|
|
</div>
|
|
<el-tabs
|
|
v-model="editableTabsValue"
|
|
type="card"
|
|
closable
|
|
@tab-remove="removeTab"
|
|
>
|
|
<el-tab-pane
|
|
v-for="item in editableTabs"
|
|
:key="item.name"
|
|
:label="item.title"
|
|
:name="item.name"
|
|
>
|
|
{{ item.content }}
|
|
</el-tab-pane>
|
|
</el-tabs>
|
|
</template>
|
|
<script lang="ts">
|
|
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: {
|
|
addTab(targetName) {
|
|
const newTabName = `${++this.tabIndex}`
|
|
this.editableTabs.push({
|
|
title: 'New Tab',
|
|
name: newTabName,
|
|
content: 'New Tab content',
|
|
})
|
|
this.editableTabsValue = newTabName
|
|
},
|
|
removeTab(targetName) {
|
|
const tabs = this.editableTabs
|
|
let activeName = this.editableTabsValue
|
|
if (activeName === targetName) {
|
|
tabs.forEach((tab, index) => {
|
|
if (tab.name === targetName) {
|
|
const nextTab = tabs[index + 1] || tabs[index - 1]
|
|
if (nextTab) {
|
|
activeName = nextTab.name
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
this.editableTabsValue = activeName
|
|
this.editableTabs = tabs.filter((tab) => tab.name !== targetName)
|
|
},
|
|
},
|
|
}
|
|
</script>
|