最近項目中遇到一個問題,使用elementui級聯組件與後臺聯調是返回的數據裏面沒有label和value,這時頁面不會顯示,在不改變原生組件的情況下,我們可以利用遞歸對數據進項處理,每個裏面都加上label和value。
methods(){
findChildren(node) {
node.forEach((ele, index) => {
const children = ele.children;
ele.value = ele.code;
ele.label = ele.name;
if (children) {
this.findChildren(children);
}
});
}
}
在相應的地方調用此方法,把要處理的數據傳進去,例如我的業務是在調用接口後請求的時候對數據進行處理
postDictoryData1(param).then(data => {
console.log("欄目獲取詞條", data);
this.findChildren(data.entityList);
this.wordEntryList = data.entityList;
console.log("citiooo", this.wordEntryList)
});