Commit cd8f1be8399202babd223633d4459bb2b51b6c50
1 parent
bef01c91
fixed bug #4466 #4300
Showing
2 changed files
with
18 additions
and
2 deletions
Show diff stats
examples/routers/select.vue
| @@ -7,6 +7,8 @@ | @@ -7,6 +7,8 @@ | ||
| 7 | <Select v-model="model2" multiple style="width:200px"> | 7 | <Select v-model="model2" multiple style="width:200px"> |
| 8 | <Option v-for="item in cityList" :value="item.value" :key="item.value">{{ item.label }}</Option> | 8 | <Option v-for="item in cityList" :value="item.value" :key="item.value">{{ item.label }}</Option> |
| 9 | </Select> | 9 | </Select> |
| 10 | + | ||
| 11 | + <Button type="primary" @click="changeData">changeData</Button> | ||
| 10 | </div> | 12 | </div> |
| 11 | </template> | 13 | </template> |
| 12 | <script> | 14 | <script> |
| @@ -42,6 +44,11 @@ | @@ -42,6 +44,11 @@ | ||
| 42 | model1: '', | 44 | model1: '', |
| 43 | model2: [] | 45 | model2: [] |
| 44 | } | 46 | } |
| 47 | + }, | ||
| 48 | + methods: { | ||
| 49 | + changeData() { | ||
| 50 | + this.model2.push('Canberra') | ||
| 51 | + } | ||
| 45 | } | 52 | } |
| 46 | } | 53 | } |
| 47 | </script> | 54 | </script> |
src/components/select/select.vue
| @@ -135,6 +135,15 @@ | @@ -135,6 +135,15 @@ | ||
| 135 | return textContent || (typeof innerHTML === 'string' ? innerHTML : ''); | 135 | return textContent || (typeof innerHTML === 'string' ? innerHTML : ''); |
| 136 | }; | 136 | }; |
| 137 | 137 | ||
| 138 | + const checkValuesNotEqual = (value,publicValue,values) => { | ||
| 139 | + const strValue = JSON.stringify(value); | ||
| 140 | + const strPublic = JSON.stringify(publicValue); | ||
| 141 | + const strValues = JSON.stringify(values.map( item => { | ||
| 142 | + return item.value; | ||
| 143 | + })); | ||
| 144 | + return strValue !== strPublic || strValue !== strValues || strValues !== strPublic; | ||
| 145 | + }; | ||
| 146 | + | ||
| 138 | 147 | ||
| 139 | const ANIMATION_TIMEOUT = 300; | 148 | const ANIMATION_TIMEOUT = 300; |
| 140 | 149 | ||
| @@ -653,12 +662,12 @@ | @@ -653,12 +662,12 @@ | ||
| 653 | }, | 662 | }, |
| 654 | watch: { | 663 | watch: { |
| 655 | value(value){ | 664 | value(value){ |
| 656 | - const {getInitialValue, getOptionData, publicValue} = this; | 665 | + const {getInitialValue, getOptionData, publicValue, values} = this; |
| 657 | 666 | ||
| 658 | this.checkUpdateStatus(); | 667 | this.checkUpdateStatus(); |
| 659 | 668 | ||
| 660 | if (value === '') this.values = []; | 669 | if (value === '') this.values = []; |
| 661 | - else if (JSON.stringify(value) !== JSON.stringify(publicValue)) { | 670 | + else if (checkValuesNotEqual(value,publicValue,values)) { |
| 662 | this.$nextTick(() => this.values = getInitialValue().map(getOptionData).filter(Boolean)); | 671 | this.$nextTick(() => this.values = getInitialValue().map(getOptionData).filter(Boolean)); |
| 663 | } | 672 | } |
| 664 | }, | 673 | }, |