------------恢復內容開始------------
我在使用elements-ui的時候,用到了<el-cascader>級聯選擇器,數據格式按要求是 value和lable,我用的是以前的接口,以前數據給的是id和name,不能修改數據參數,所以需要自己給重新組裝一下數據格式。
因為數據里面有幾層函數(不確定),所以最好的方法就是遞歸函數。
原始數據長這樣:里面有多層children

在mutations里面進行數據遞歸修改:
在mutation里面定義一個function函數 modify(),判斷是否存在children,如果存在則遞歸modify(),否則就直接修改value和lable
quaryTreeList(state,result){
function modify(result){
result.map(item => {
if(item.children){ // 遞歸調用
modify(item.children);
}
item.value = item.id;
item.label = item.name;
return item;
});
return result;
}
modify(result);
console.log('修改后的result===', result);
state.treeSelectListResult = result;
}
