elmentplus中刪除el-treen 資料時,樹的資料改變了,但是樹不重新整理

sinceForever發表於2024-08-21
<el-tree
    ref="treeRef"
    style="max-width: 600px"
    class="filter-tree"
    :data="treeData"
    :props="defaultProps"
    default-expand-all
    :filter-node-method="filterNode"
    node-key="id"
    @node-click="handleNodeClick"
  />
const treeRef = ref<InstanceType<typeof ElTree>>();

const handleDelete = (ids: string) => {
  ElMessageBox.confirm("確定刪除嗎?", "提示", {
    confirmButtonText: "確定",
    cancelButtonText: "取消",
    type: "warning",
  }).then(() => {
    deleteApi(ids).then(async () => {
      // 重新整理樹
      await getTreeData();
      //刪除時,樹的資料改變了,但是樹不重新整理,需要手動呼叫樹的remove方法
      if (treeRef.value) {
        treeRef.value.remove(currentTreeItem);
      }
      ElMessage.success("操作成功");
    });
  });
};

相關文章