<el-cascader :options="areaTree"
change-on-select
:props="areaProps"
v-model="value"
@change="changeArea">
</el-cascader>
<script>
...
data(){
return{
value: '',
areaProps: {
label: 'name',
value: 'id'
},
}
},
methods:{
getAreaTree () {
area.tree().then(res => {
this.areaTree = this.getChildsData (res.data);
})
},
getChildsData (data) {
for (var i = 0; i < data.length; i++) {
if (data[i].children== null || data[i].children.length < 1) {
data[i].children= undefined;
} else {
this.getChildsData(data[i].children);
}
}
return data;
}
}
</script>
getChildsData()方法解决空级联