fix(components): [tree-v2] set expanded keys requires multiple nextTick (#20725)

This commit is contained in:
xingyixiang
2025-05-15 23:58:19 +08:00
committed by GitHub
parent 9a82272e1f
commit 21fda1e55f

View File

@@ -1,4 +1,4 @@
import { computed, nextTick, ref, shallowRef, watch } from 'vue'
import { computed, ref, shallowRef, watch } from 'vue'
import { isObject } from '@element-plus/utils'
import {
CURRENT_CHANGE,
@@ -35,26 +35,6 @@ export function useTree(
const tree = shallowRef<Tree | undefined>()
const listRef = ref<typeof FixedSizeList | undefined>()
watch(
() => props.currentNodeKey,
(key) => {
currentKey.value = key
},
{
immediate: true,
}
)
watch(
() => props.data,
(data: TreeData) => {
setData(data)
},
{
immediate: true,
}
)
const {
isIndeterminate,
isChecked,
@@ -288,7 +268,7 @@ export function useTree(
}
function setData(data: TreeData) {
nextTick(() => (tree.value = createTree(data)))
tree.value = createTree(data)
}
function getNode(data: TreeKey | TreeNodeData) {
@@ -307,6 +287,26 @@ export function useTree(
listRef.value?.scrollTo(offset)
}
watch(
() => props.currentNodeKey,
(key) => {
currentKey.value = key
},
{
immediate: true,
}
)
watch(
() => props.data,
(data: TreeData) => {
setData(data)
},
{
immediate: true,
}
)
return {
tree,
flattenTree,