소스 검색

fix: preserve tree default value when treeData starts empty (#7908)

When treeData is initially an empty array (e.g. before async data
arrives), updateTreeValue() would clear the modelValue because no
matching items could be found in the empty flattened data. This caused
default values to be lost.

Only call updateTreeValue() when flattenData has items, so that
modelValue is preserved until the actual tree data arrives.

Fixes #6522
Akuria 4 주 전
부모
커밋
ca5931e8c4
2개의 변경된 파일8개의 추가작업 그리고 1개의 파일을 삭제
  1. 5 0
      .changeset/tree-default-value.md
  2. 3 1
      packages/@core/ui-kit/shadcn-ui/src/ui/tree/tree.vue

+ 5 - 0
.changeset/tree-default-value.md

@@ -0,0 +1,5 @@
+---
+"@vben-core/shadcn-ui": patch
+---
+
+fix: preserve tree default value when treeData starts empty

+ 3 - 1
packages/@core/ui-kit/shadcn-ui/src/ui/tree/tree.vue

@@ -70,7 +70,9 @@ let lastTreeData: any = null;
 onMounted(() => {
   watchEffect(() => {
     flattenData.value = flatten(props.treeData, props.childrenField);
-    updateTreeValue();
+    if (flattenData.value.length > 0) {
+      updateTreeValue();
+    }
 
     // 只在 treeData 变化时执行展开
     const currentTreeData = JSON.stringify(props.treeData);