上圖所示,后端返回字段中有hasChildren字段。
解決樹狀表格失效方案:
從后端拿到數據后,遞歸去掉該字段,然后就能正常顯示。(復制下方代碼,直接用)
親測有效,vue2、vue3通用
/**遞歸函數 */
function recursion(data: Array<any>) {if (data.length) {data.forEach((element: any) => {delete element.hasChildrenif ("children" in element) {recursion(element.children);}});}
}