代碼如下:
?:props="optionProps"? //如果配置了這個選項,請求回來的數據,根本不用你去遞歸處理,只需要把響應的數據賦值給數據源cateList
<el-cascader v-model="cateValue" :options="cateList" :props="cateListProps" > </el-cascader>
data中:
cateList: [], //數據源
cateListProps: {
? ? ? ?value: 'id', //匹配響應數據中的id
? ? ? ?label: 'name', //匹配響應數據中的name
? ? ? ?children: 'children' //匹配響應數據中的children }?
重點
let department=new RegExp('department','g')? //獲取全部的 department
data.replace(department,' name ')? ?//將其他級別的 department(label)替換成統一名字 name(label)
然后將值this. cateList = data