Skip to content

Commit efed4c7

Browse files
committed
fix: deep prop support reactive.
1 parent 247949b commit efed4c7

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

src/components/Tree/index.vue

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,7 @@ export default {
182182
return {
183183
translateY: 0,
184184
visibleData: null,
185-
hiddenPaths: jsonFlatten(this.data, this.rootPath).reduce((acc, item) => {
186-
const depthComparison = item.level >= this.deep;
187-
if ((item.type === 'objectStart' || item.type === 'arrayStart') && depthComparison) {
188-
return {
189-
...acc,
190-
[item.path]: 1,
191-
};
192-
}
193-
return acc;
194-
}, {}),
185+
hiddenPaths: this.initHiddenPaths(jsonFlatten(this.data, this.rootPath), this.deep),
195186
};
196187
},
197188
computed: {
@@ -271,21 +262,25 @@ export default {
271262
},
272263
273264
deep: {
274-
handler() {
275-
this.hiddenPaths = jsonFlatten(this.data, this.rootPath).reduce((acc, item) => {
276-
const depthComparison = item.level >= this.deep;
277-
if ((item.type === 'objectStart' || item.type === 'arrayStart') && depthComparison) {
278-
return {
279-
...acc,
280-
[item.path]: 1,
281-
};
282-
}
283-
return acc;
284-
}, {});
265+
handler(val) {
266+
this.hiddenPaths = this.initHiddenPaths(this.originFlatData, val);
285267
},
286268
},
287269
},
288270
methods: {
271+
initHiddenPaths(originFlatData, deep) {
272+
return originFlatData.reduce((acc, item) => {
273+
const depthComparison = item.level >= deep;
274+
if ((item.type === 'objectStart' || item.type === 'arrayStart') && depthComparison) {
275+
return {
276+
...acc,
277+
[item.path]: 1,
278+
};
279+
}
280+
return acc;
281+
}, {});
282+
},
283+
289284
updateVisibleData(flatDataValue) {
290285
if (this.virtual) {
291286
const visibleCount = this.height / this.itemHeight;

0 commit comments

Comments
 (0)