- 删除子级刷新列表子级依然显示
2.更新状态子级列表未刷新
3.编辑子级后刷新页面显示状态未变更
el-table 树表格load源码
首先,load可以执行,但是只剩一个子节点就有问题,那么就直接可以定位bug在load方法里:
文件路径:element-plus\packages\components\table\src\store\tree.ts
const loadData = (row: T, key: string, treeNode) => {
const { load } = instance.props as unknown as TableProps<T>
if (load && !treeData.value[key].loaded) {
treeData.value[key].loading = true
load(row, treeNode, (data) => {
if (!Array.isArray(data)) {
throw new TypeError('[ElTable] data must be an array')
}
treeData.value[key].loading = false
treeData.value[key].loaded = true
treeData.value[key].expanded = true
// 就是这里,我们的子节点删完了data.length == 0,无法赋值
if (data.length) {
lazyTreeNodeMap.value[key] = data
}
instance.emit('expand-change', row, true)
})
}
}
增加方法手动刷新子级数据
// 刷新时
const refreshChild = (parentId) => {
if (rowMaps.get(parentId)) {
const { tree, treeNode, resolve } = rowMaps.get(parentId);
handleLoadTableChild(tree, treeNode, resolve);
} else {
sysTemp.value.getTableData();
}
};
// 先new一个map用于数据保存
const rowMaps = reactive(new Map());
load加载时存储父级id及数据信息
rowMaps.set(tree.id, { tree, treeNode, resolve });