elementui el-cascader内部没有处理子数据为空数组的逻辑,所以我们要自己递归数据,把空数组的子元素清掉,当数据量特别大的时候,我认为会很耗性能,但是目前没别的办法。
// An highlighted block
<el-cascader
ref="deviceTypeCascader"
v-model="form.deviceTypeCode" //绑定的值
clearable//是否显示清除按钮
:show-all-levels="false"//是否展示完整路径
:options="deviceTypeCodeMap"//展示数据
:props="deviceTypeProps"//配置选项
/>
// An highlighted block
data() {
return {
deviceTypeProps: {
label: 'typeName',//标签名称
children: 'nextList',//子元素数组数据
value: 'typeCode',//选中的属性值
emitPath: false //在选中节点改变时,是否返回由该节点所在的各级菜单的值所组成的数组,若设置 false,则只返回该节点的值
},
}
}
// An highlighted block
//递归设备类型多级列表,删除nextList空数组
recursion(res){
res.forEach(item => {
if(item['nextList'].length){
this.recursion(item['nextList'])
}else{
delete item['nextList'];
}
});
},
在接口回调里拿到数据再去做递归清除