Commit 0922fc36 authored by baiyaaaaa's avatar baiyaaaaa Committed by cinwell.li

fix tab remove bug (#2106)

parent ef2e3c69
...@@ -20,14 +20,24 @@ ...@@ -20,14 +20,24 @@
}, },
watch: { watch: {
activeName(val) { activeName(value) {
this.currentName = val; this.setCurrentName(value);
}, },
value(val) { value(value) {
this.currentName = val; this.setCurrentName(value);
}, }
currentName(val) { },
this.$emit('input', val);
computed: {
currentTab() {
if (!this.$children) return;
let result;
this.$children.forEach(tab => {
if (this.currentName === (tab.name || tab.index)) {
result = tab;
}
});
return result;
} }
}, },
...@@ -35,6 +45,7 @@ ...@@ -35,6 +45,7 @@
handleTabRemove(tab, event) { handleTabRemove(tab, event) {
event.stopPropagation(); event.stopPropagation();
const tabs = this.$children; const tabs = this.$children;
const currentTab = this.currentTab;
let index = tabs.indexOf(tab); let index = tabs.indexOf(tab);
tab.$destroy(); tab.$destroy();
...@@ -49,15 +60,22 @@ ...@@ -49,15 +60,22 @@
let nextActiveTab = nextChild || prevChild || null; let nextActiveTab = nextChild || prevChild || null;
if (nextActiveTab) { if (nextActiveTab) {
this.currentName = nextActiveTab.name || nextActiveTab.index; this.setCurrentName(nextActiveTab.name || nextActiveTab.index);
} }
return;
} else {
this.setCurrentName(currentTab.name || currentTab.index);
} }
}); });
}, },
handleTabClick(tab, tabName, event) { handleTabClick(tab, tabName, event) {
if (tab.disabled) return; if (tab.disabled) return;
this.currentName = tabName; this.setCurrentName(tabName);
this.$emit('tab-click', tab, event); this.$emit('tab-click', tab, event);
},
setCurrentName(value) {
this.currentName = value;
this.$emit('input', value);
} }
}, },
mounted() { mounted() {
...@@ -99,7 +117,7 @@ ...@@ -99,7 +117,7 @@
const tabs = this.$children.map((tab, index) => { const tabs = this.$children.map((tab, index) => {
let tabName = tab.name || tab.index || index; let tabName = tab.name || tab.index || index;
if (currentName === undefined && index === 0) { if (currentName === undefined && index === 0) {
this.currentName = tabName; this.setCurrentName(tabName);
} }
tab.index = index; tab.index = index;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment