diff --git a/README.md b/README.md index f364694..4146376 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,7 @@ plugins: [ | ------------------------ | ------ | --------------------------------------------------------------------------------------- | ---------------------------------------------- | -------- | | data | normal | JSON data | JSON object | - | | deep | normal | Data depth, data larger than this depth will not be expanded | number | Infinity | +| deepCollapseChildren | normal | Whether children collapsed by `deep` prop should also be collapsed | boolean | false | | showLength | normal | Whether to show the length when closed | boolean | false | | showLine | normal | Whether to show the line | boolean | true | | showDoubleQuotes | normal | Whether to show doublequotes on key | boolean | true | diff --git a/src/components/Tree/index.vue b/src/components/Tree/index.vue index 0af6508..bcd0ee1 100644 --- a/src/components/Tree/index.vue +++ b/src/components/Tree/index.vue @@ -55,6 +55,10 @@ export default { type: Number, default: Infinity, }, + deepCollapseChildren: { + type: Boolean, + default: false, + }, // 数据层级顶级路径 path: { type: String, @@ -129,9 +133,12 @@ export default { translateY: 0, visibleData: null, hiddenPaths: jsonFlatten(this.data, this.path).reduce((acc, item) => { + const depthComparison = this.deepCollapseChildren + ? item.level >= this.deep + : item.level === this.deep; if ( (item.type === 'objectStart' || item.type === 'arrayStart') && - item.level === this.deep + depthComparison ) { return { ...acc,