vue中使用elementui級聯組件常見的數據處理問題

最近項目中遇到一個問題,使用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)
      });

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章