Commit 5dc44ccf9b3fc19df3a758901f0bdd5020953bf8
1 parent
a73ae72b
fixed #2793
Showing
2 changed files
with
16 additions
and
13 deletions
Show diff stats
examples/routers/cascader.vue
1 | 1 | <template> |
2 | - <Cascader v-model="value3" :data="data" filterable @on-change="hc"></Cascader> | |
2 | + <div style="margin: 100px;width: 300px;"> | |
3 | + <Cascader v-model="value" :data="data" change-on-select></Cascader> | |
4 | + </div> | |
3 | 5 | </template> |
4 | 6 | <script> |
5 | 7 | export default { |
6 | 8 | data () { |
7 | 9 | return { |
8 | - data: [{ | |
10 | + value: ['beijing', 'gugong'], | |
11 | + data: [] | |
12 | + } | |
13 | + }, | |
14 | + mounted () { | |
15 | + setTimeout(() => { | |
16 | + this.data = [{ | |
9 | 17 | value: 'beijing', |
10 | 18 | label: '北京', |
11 | 19 | children: [ |
... | ... | @@ -51,14 +59,8 @@ |
51 | 59 | ] |
52 | 60 | } |
53 | 61 | ], |
54 | - }], | |
55 | - value3: [] | |
56 | - } | |
57 | - }, | |
58 | - methods: { | |
59 | - hc (a,b) { | |
60 | - console.log(a,b) | |
61 | - } | |
62 | + }]; | |
63 | + }, 100) | |
62 | 64 | } |
63 | 65 | } |
64 | 66 | </script> | ... | ... |
src/components/cascader/cascader.vue
... | ... | @@ -258,8 +258,9 @@ |
258 | 258 | updateResult (result) { |
259 | 259 | this.tmpSelected = result; |
260 | 260 | }, |
261 | - updateSelected (init = false) { | |
262 | - if (!this.changeOnSelect || init) { | |
261 | + updateSelected (init = false, changeOnSelectDataChange = false) { | |
262 | + // #2793 changeOnSelectDataChange used for changeOnSelect when data changed and set value | |
263 | + if (!this.changeOnSelect || init || changeOnSelectDataChange) { | |
263 | 264 | this.broadcast('Caspanel', 'on-find-selected', { |
264 | 265 | value: this.currentValue |
265 | 266 | }); |
... | ... | @@ -386,7 +387,7 @@ |
386 | 387 | if (validDataStr !== this.validDataStr) { |
387 | 388 | this.validDataStr = validDataStr; |
388 | 389 | if (!this.isLoadedChildren) { |
389 | - this.$nextTick(() => this.updateSelected()); | |
390 | + this.$nextTick(() => this.updateSelected(false, this.changeOnSelect)); | |
390 | 391 | } |
391 | 392 | this.isLoadedChildren = false; |
392 | 393 | } | ... | ... |