From f71a1da8a743a7cc0b47f3c56d04c813cc150982 Mon Sep 17 00:00:00 2001 From: chenjiahan Date: Sun, 20 Dec 2020 21:14:14 +0800 Subject: [PATCH] fix(Cascader): failed to switch to active tab --- src/cascader/index.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/cascader/index.js b/src/cascader/index.js index 21209bce4..31b771623 100644 --- a/src/cascader/index.js +++ b/src/cascader/index.js @@ -3,15 +3,18 @@ import Tab from '../tab'; import Tabs from '../tabs'; import Icon from '../icon'; -const [createComponent, bem] = createNamespace('cascader'); +const [createComponent, bem, t] = createNamespace('cascader'); export default createComponent({ props: { title: String, value: [Number, String], - options: Array, placeholder: String, activeColor: String, + options: { + type: Array, + default: () => [], + }, closeable: { type: Boolean, default: true, @@ -99,7 +102,9 @@ export default createComponent({ }); } - this.activeTab = this.tabs.length - 1; + this.$nextTick(() => { + this.activeTab = this.tabs.length - 1; + }); return; } @@ -137,10 +142,14 @@ export default createComponent({ }); } + const selectedOptions = this.tabs + .map((tab) => tab.selectedOption) + .filter((item) => !!item); + const eventParams = { value: option.value, tabIndex, - selectedOptions: this.tabs.map((tab) => tab.selectedOption), + selectedOptions, }; this.$emit('input', option.value); this.$emit('change', eventParams); @@ -197,7 +206,7 @@ export default createComponent({ const { options, selectedOption } = item; const title = selectedOption ? selectedOption.text - : this.placeholder || this.t('select'); + : this.placeholder || t('select'); return (