diff --git a/packages/components/tree-v2/src/composables/useTree.ts b/packages/components/tree-v2/src/composables/useTree.ts index 1ab847a01f..bf5a47516f 100644 --- a/packages/components/tree-v2/src/composables/useTree.ts +++ b/packages/components/tree-v2/src/composables/useTree.ts @@ -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() const listRef = ref() - 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,