Skip to content

Commit 4be8286

Browse files
committed
feat: 新增默认展开层级 prop(expand-deep)
1 parent a51658a commit 4be8286

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

Diff for: src/json-tree/JsonTree.vue

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
<JsonTreeNode ref="jsonTreeNode"
44
:json-data="jsonData"
55
:show-line="showLine"
6-
:indent="indent">
6+
:indent="indent"
7+
:expand-deep="expandDeep">
78
<template v-for="(_, slot) of $scopedSlots"
89
v-slot:[slot]="scope">
910
<slot :name="slot" v-bind="scope"></slot>
@@ -35,6 +36,11 @@ export default {
3536
indent: {
3637
type: [String, Number],
3738
default: '20px'
39+
},
40+
// 默认展开的层级
41+
expandDeep: {
42+
type: Number,
43+
default: 2
3844
}
3945
},
4046
methods: {

Diff for: src/json-tree/JsonTreeNode.vue

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
:json-keys="[...jsonKeys, i]"
102102
:json-data="childData"
103103
:indent="indent"
104+
:expand-deep="expandDeep"
104105
:deep="deep + 1"
105106
:show-line="showLine">
106107
<template v-for="(_, slot) of $scopedSlots"

Diff for: src/json-tree/json-tree-node.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ export default {
1212
type: [String, Number],
1313
default: '20px'
1414
},
15+
// 默认展开的层级
16+
expandDeep: {
17+
type: Number,
18+
default: 2
19+
},
1520
jsonKey: {
1621
type: [String, Number]
1722
},
@@ -30,8 +35,14 @@ export default {
3035
}
3136
},
3237
data () {
38+
const { deep, expandDeep } = this
39+
let localCollapse = !!this.collapse
40+
if (deep < expandDeep) {
41+
localCollapse = false
42+
}
43+
3344
return {
34-
localCollapse: !!this.collapse
45+
localCollapse
3546
}
3647
},
3748
computed: {

0 commit comments

Comments
 (0)