docs(Cascader): add demos

This commit is contained in:
chenjiahan
2020-12-20 21:23:50 +08:00
committed by neverland
parent 04d6561315
commit 4c1c786ae6
8 changed files with 255 additions and 14 deletions
+52 -1
View File
@@ -17,9 +17,24 @@ Vue.use(Cascader);
### 基础用法
级联选择组件可以搭配 Field 和 Popup 组件使用,示例如下:
```html
<van-field
is-link
readonly
label="地区"
:value="fieldValue"
placeholder="请选择地区"
@click="show = true"
/>
<van-popup v-model="show" round position="bottom">
<van-cascader title="请选择地区" />
<van-cascader
v-model="cascaderValue"
title="请选择地区"
@close="show = false"
@finish="onFinish"
/>
</van-popup>
```
@@ -28,11 +43,47 @@ export default {
data() {
return {
show: false,
fieldValue: '',
cascaderValue: '',
// 选项列表,children 代表子选项,支持多级嵌套
options: [
{
text: '浙江省',
value: '330000',
children: [{ text: '杭州市', value: '330100' }],
},
{
text: '江苏省',
value: '320000',
children: [{ text: '南京市', value: '320100' }],
},
],
};
},
methods: {
// 全部选项选择完毕后,会触发 finish 事件
onFinish(params) {
const { selectedOptions } = params;
this.fieldValue = selectedOptions.map((option) => option.text).join('/');
},
},
};
```
### 自定义颜色
通过 `active-color` 属性来设置选中状态的高亮颜色。
```html
<van-cascader
v-model="cascaderValue"
title="请选择地区"
active-color="#1989fa"
@close="show = false"
@finish="onFinish"
/>
```
## API
### Props