3
3
reactive ,
4
4
computed ,
5
5
watchEffect ,
6
+ watch ,
6
7
ref ,
7
8
PropType ,
8
9
CSSProperties ,
@@ -83,11 +84,9 @@ export default defineComponent({
83
84
84
85
const originFlatData = computed ( ( ) => jsonFlatten ( props . data , props . rootPath ) ) ;
85
86
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 ;
91
90
const pathComparison = props . pathCollapsible ?.( item as NodeDataType ) ;
92
91
if (
93
92
( item . type === 'objectStart' || item . type === 'arrayStart' ) &&
@@ -99,7 +98,13 @@ export default defineComponent({
99
98
} ;
100
99
}
101
100
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 ) ,
103
108
} ) ;
104
109
105
110
const flatData = computed ( ( ) => {
@@ -247,6 +252,13 @@ export default defineComponent({
247
252
}
248
253
} ) ;
249
254
255
+ watch (
256
+ ( ) => props . deep ,
257
+ val => {
258
+ if ( val ) state . hiddenPaths = initHiddenPaths ( val ) ;
259
+ } ,
260
+ ) ;
261
+
250
262
return ( ) => {
251
263
const renderNodeKey = props . renderNodeKey ?? slots . renderNodeKey ;
252
264
const renderNodeValue = props . renderNodeValue ?? slots . renderNodeValue ;
0 commit comments