Tabs: rerender when slot changes (#15238)

pull/15190/head^2
hetech 2019-04-24 11:32:42 +08:00 committed by iamkun
parent 73ca7be647
commit 0325e1dc4d
2 changed files with 5 additions and 7 deletions

View File

@ -49,10 +49,8 @@
}
},
watch: {
label() {
this.$parent.$emit('tabLabelChanged');
}
updated() {
this.$parent.$emit('tab-nav-update');
}
};
</script>

View File

@ -55,14 +55,14 @@
},
methods: {
calcPaneInstances(isLabelUpdated = false) {
calcPaneInstances(isForceUpdate = false) {
if (this.$slots.default) {
const paneSlots = this.$slots.default.filter(vnode => vnode.tag &&
vnode.componentOptions && vnode.componentOptions.Ctor.options.name === 'ElTabPane');
// update indeed
const panes = paneSlots.map(({ componentInstance }) => componentInstance);
const panesChanged = !(panes.length === this.panes.length && panes.every((pane, index) => pane === this.panes[index]));
if (isLabelUpdated || panesChanged) {
if (isForceUpdate || panesChanged) {
this.panes = panes;
}
} else if (this.panes.length !== 0) {
@ -177,7 +177,7 @@
this.setCurrentName('0');
}
this.$on('tabLabelChanged', this.calcPaneInstances.bind(null, true));
this.$on('tab-nav-update', this.calcPaneInstances.bind(null, true));
},
mounted() {