在开发过程中需要用到element组件中的el-cascader级联选择器,级联选择器的数据是从后端接口拿到的,有时候接口返回的数据最后是一个空数组,这时候我要前端去处理一下数据,下面是处理的方法
下面展示一些 内联代码片
。
html代码
<template>
<div>
<el-cascader
v-model="addQuestionForm.questionCategory"
:options="categoryList"
:props="choseCateProps"
clearable
@change="choseCateHandle"
>
</el-cascader>
</div>
</template>
js代码
下面展示一些 内联代码片
。
export default {
data(){
return{
categoryList:[]
}
}
}
created(){
this.getCategoryList();
},
method:{
//调接口获取数据列表
getCategoryList() {
console.log("请求前的value", this.addQuestionForm.questionCategory);
this.$http({
url: "/knewdata-ecp/qyapp/questionCategory/categoryList",
method: "get",
}).then(({ data }) => {
console.log("获取新的分类数据", data);
if (data && data.code === 200) {
this.categoryList = this.getTreeData(data.data);
console.log(this.categoryList);
}
});
},
}