diff --git a/packages/components/table/src/store/tree.ts b/packages/components/table/src/store/tree.ts index 4c6b899fd9..f2558199ba 100644 --- a/packages/components/table/src/store/tree.ts +++ b/packages/components/table/src/store/tree.ts @@ -161,7 +161,9 @@ function useTree(watcherData: WatcherPropsData) { expandRowKeys.value = value updateTreeData() } - + const isUseLazy = (data): boolean => { + return lazy.value && data && 'loaded' in data && !data.loaded + } const toggleTreeExpansion = (row: T, expanded?: boolean) => { instance.store.assertRowKey() @@ -175,6 +177,7 @@ function useTree(watcherData: WatcherPropsData) { if (oldExpanded !== expanded) { instance.emit('expand-change', row, expanded) } + isUseLazy(data) && loadData(row, id, data) instance.store.updateTableScrollY() } } @@ -184,7 +187,7 @@ function useTree(watcherData: WatcherPropsData) { const rowKey = watcherData.rowKey.value const id = getRowIdentity(row, rowKey) const data = treeData.value[id] - if (lazy.value && data && 'loaded' in data && !data.loaded) { + if (isUseLazy(data)) { loadData(row, id, data) } else { toggleTreeExpansion(row, undefined)