Commit 0325e1dc authored by hetech's avatar hetech Committed by iamkun

Tabs: rerender when slot changes (#15238)

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