fix(Cascader): should watch options deeply (#7777)

* fix(Cascader): should watch options deeply

* docs: fix
This commit is contained in:
neverland
2020-12-21 10:28:08 +08:00
committed by GitHub
parent 5452701c47
commit a9134162f6
5 changed files with 196 additions and 6 deletions
+59 -2
View File
@@ -54,8 +54,8 @@ export default {
};
},
methods: {
onFinish(params) {
const { selectedOptions } = params;
onFinish({ selectedOptions }) {
this.show = false;
this.fieldValue = selectedOptions.map((option) => option.text).join('/');
},
},
@@ -74,6 +74,63 @@ export default {
/>
```
### Async Options
```html
<van-field
is-link
readonly
label="Area"
:value="fieldValue"
placeholder="Select Area"
@click="show = true"
/>
<van-popup v-model="show" round position="bottom">
<van-cascader
v-model="cascaderValue"
title="Select Area"
@close="show = false"
@change="onChange"
@finish="onFinish"
/>
</van-popup>
```
```js
export default {
data() {
return {
show: false,
fieldValue: '',
cascaderValue: '',
options: [
{
text: 'Zhejiang',
value: '330000',
children: [],
},
],
};
},
methods: {
onChange({ value }) {
if (value === this.options[0].value) {
setTimeout(() => {
this.options[0].children = [
{ text: 'Hangzhou', value: '330100' },
{ text: 'Ningbo', value: '330200' },
];
}, 500);
}
},
onFinish({ selectedOptions }) {
this.show = false;
this.fieldValue = selectedOptions.map((option) => option.text).join('/');
},
},
};
```
## API
### Props