diff --git a/src/components/tabs/pane.vue b/src/components/tabs/pane.vue index a5837af4..7a14a768 100644 --- a/src/components/tabs/pane.vue +++ b/src/components/tabs/pane.vue @@ -25,7 +25,11 @@ closable: { type: Boolean, default: null - } + }, + // Tabs 嵌套时,用 tab 区分层级,指向对应的 Tabs 的 name + tab: { + type: String + }, }, data () { return { diff --git a/src/components/tabs/tabs.vue b/src/components/tabs/tabs.vue index b3233f58..b3e80629 100644 --- a/src/components/tabs/tabs.vue +++ b/src/components/tabs/tabs.vue @@ -96,6 +96,10 @@ default: false }, beforeRemove: Function, + // Tabs 嵌套时,用 name 区分层级 + name: { + type: String + }, }, data () { return { @@ -170,7 +174,20 @@ methods: { getTabs () { // return this.$children.filter(item => item.$options.name === 'TabPane'); - return findComponentsDownward(this, 'TabPane'); + const AllTabPanes = findComponentsDownward(this, 'TabPane'); + const TabPanes = []; + + AllTabPanes.forEach(item => { + if (item.tab && this.name) { + if (item.tab === this.name) { + TabPanes.push(item); + } + } else { + TabPanes.push(item); + } + }); + + return TabPanes; }, updateNav () { this.navList = [];