el-cascader中最后一级显示为空是因为从后端接口获取的数据最后一个children为空
<el-cascader
:options="treeDeptData"
style="width:200px"
></el-cascader>
在调用接口数据的方法中赋值
if (response.data.code === 0) {
this.treeDeptData = this.getTreeData(response.data.data)
}
getTreeData(data){
for(var i=0;i<data.length;i++){
if(data[i].children.length<1){
// children若为空数组,则将children设为undefined
data[i].children=undefined;
}else {
this.getTreeData(data[i].children);
}
}
return data;
},