mirror of https://github.com/ElemeFE/element
Tabs: rerender when slot changes (#15238)
parent
73ca7be647
commit
0325e1dc4d
|
@ -49,10 +49,8 @@
|
|||
}
|
||||
},
|
||||
|
||||
watch: {
|
||||
label() {
|
||||
this.$parent.$emit('tabLabelChanged');
|
||||
}
|
||||
updated() {
|
||||
this.$parent.$emit('tab-nav-update');
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue