原因時沒有子級的時候后台返回了一個空數字 例如: children:[ ]
這時候需要遞歸將children為空的賦值為undefined
//獲取系統分類管理列表 getSystemTypeApi(){ getSystemTypeApi({}).then((res)=>{ if(res.data.code == 200){ this.systemTypeList = this.getTreeData(res.data.data); // this.systemTypeList = res.data.data; } }); }, // 遞歸判斷列表,把最后的children設為undefined getTreeData(data){ for(var i=0;i<data.length>0;i++){ if(data[i].children == null||data[i].children.length<=0){ // children若為空數組,則將children設為undefined data[i].children = undefined; }else { // children若不為空數組,則繼續 遞歸調用 本方法 this.getTreeData(data[i].children); } } return data; },