mirror of https://github.com/ElemeFE/element
fix tab remove bug (#2106)
parent
ef2e3c697a
commit
0922fc3683
|
@ -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 @@
|
||||||
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 @@
|
||||||
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 @@
|
||||||
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;
|
||||||
|
|
Loading…
Reference in New Issue