原文:https://www.jianshu.com/p/b690d7fe6ec0
注意兩點就行了
<el-form-item label="AP名稱">
<el-cascader
v-model="ruleForm.ap"
:options="apOptions"
change-on-select>
</el-cascader>
</el-form-item>
apOptions:[
{
value:'',
label: '全部'
}
,{
value: 'zhinan',
label: '指南',
children: [
{
value: 'shejiyuanze',
label: '設計原則',
children: [{
value: 'yizhi',
label: '一致'
}, {
value: 'fankui',
label: '反饋'
}, {
value: 'xiaolv',
label: '效率'
}, {
value: 'kekong',
label: '可控'
}]
}, {
value: 'daohang',
label: '導航',
children: [{
value: 'cexiangdaohang',
label: '側向導航'
}, {
value: 'dingbudaohang',
label: '頂部導航'
}]
}]
}
]
第一點v-model="ruleForm.ap"綁定得是數組
第二點設置默認值得時候設置得是label對應得value
如上面得數據我想設置默認值是全部 就要如下設置
this.ruleForm.ap = ['']
因為label對應得value是''
再舉個例子想在頁面默認顯示 指南/設計原則/一致
this.ruleForm.ap = ['zhinan','shejiyuanze','yizhi']
