Skip to content

Commit 8f509d6

Browse files
committed
fix: deep prop support reactive.
1 parent d3d1196 commit 8f509d6

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/components/Tree/index.tsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
reactive,
44
computed,
55
watchEffect,
6+
watch,
67
ref,
78
PropType,
89
CSSProperties,
@@ -83,11 +84,9 @@ export default defineComponent({
8384

8485
const originFlatData = computed(() => jsonFlatten(props.data, props.rootPath));
8586

86-
const state = reactive({
87-
translateY: 0,
88-
visibleData: null as NodeDataType[] | null,
89-
hiddenPaths: originFlatData.value.reduce((acc, item) => {
90-
const depthComparison = item.level >= props.deep;
87+
const initHiddenPaths = (deep: number) => {
88+
return originFlatData.value.reduce((acc, item) => {
89+
const depthComparison = item.level >= deep;
9190
const pathComparison = props.pathCollapsible?.(item as NodeDataType);
9291
if (
9392
(item.type === 'objectStart' || item.type === 'arrayStart') &&
@@ -99,7 +98,13 @@ export default defineComponent({
9998
};
10099
}
101100
return acc;
102-
}, {}) as Record<string, 1>,
101+
}, {}) as Record<string, 1>;
102+
};
103+
104+
const state = reactive({
105+
translateY: 0,
106+
visibleData: null as NodeDataType[] | null,
107+
hiddenPaths: initHiddenPaths(props.deep),
103108
});
104109

105110
const flatData = computed(() => {
@@ -247,6 +252,13 @@ export default defineComponent({
247252
}
248253
});
249254

255+
watch(
256+
() => props.deep,
257+
val => {
258+
if (val) state.hiddenPaths = initHiddenPaths(val);
259+
},
260+
);
261+
250262
return () => {
251263
const renderNodeKey = props.renderNodeKey ?? slots.renderNodeKey;
252264
const renderNodeValue = props.renderNodeValue ?? slots.renderNodeValue;

0 commit comments

Comments
 (0)