From cd8f1be8399202babd223633d4459bb2b51b6c50 Mon Sep 17 00:00:00 2001 From: 任珽 <shine_ren@kingdee.com> Date: Tue, 25 Sep 2018 15:04:56 +0800 Subject: [PATCH] fixed bug #4466 #4300 --- examples/routers/select.vue | 7 +++++++ src/components/select/select.vue | 13 +++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/examples/routers/select.vue b/examples/routers/select.vue index 3ba4557..725c9c1 100644 --- a/examples/routers/select.vue +++ b/examples/routers/select.vue @@ -7,6 +7,8 @@ <Select v-model="model2" multiple style="width:200px"> <Option v-for="item in cityList" :value="item.value" :key="item.value">{{ item.label }}</Option> </Select> + + <Button type="primary" @click="changeData">changeData</Button> </div> </template> <script> @@ -42,6 +44,11 @@ model1: '', model2: [] } + }, + methods: { + changeData() { + this.model2.push('Canberra') + } } } </script> diff --git a/src/components/select/select.vue b/src/components/select/select.vue index 6461c68..0e5a89b 100644 --- a/src/components/select/select.vue +++ b/src/components/select/select.vue @@ -135,6 +135,15 @@ return textContent || (typeof innerHTML === 'string' ? innerHTML : ''); }; + const checkValuesNotEqual = (value,publicValue,values) => { + const strValue = JSON.stringify(value); + const strPublic = JSON.stringify(publicValue); + const strValues = JSON.stringify(values.map( item => { + return item.value; + })); + return strValue !== strPublic || strValue !== strValues || strValues !== strPublic; + }; + const ANIMATION_TIMEOUT = 300; @@ -653,12 +662,12 @@ }, watch: { value(value){ - const {getInitialValue, getOptionData, publicValue} = this; + const {getInitialValue, getOptionData, publicValue, values} = this; this.checkUpdateStatus(); if (value === '') this.values = []; - else if (JSON.stringify(value) !== JSON.stringify(publicValue)) { + else if (checkValuesNotEqual(value,publicValue,values)) { this.$nextTick(() => this.values = getInitialValue().map(getOptionData).filter(Boolean)); } }, -- libgit2 0.21.4