Skip to content

Commit dc955c5

Browse files
committed
fixed: 子树为对象时,没有显示 key 名的问题
1 parent f244730 commit dc955c5

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-json-pretty",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "A Vue.js project",
55
"author": "leezng <[email protected]>",
66
"main": "vue-json-pretty.js",

src/components/tree.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
:data="data"
66
:index="index"
77
:last-index="lastIndex">
8-
<span v-if="child && Array.isArray(data)">{{ index }}:</span>
8+
<span v-if="child && !Array.isArray(json)">{{ index }}:</span>
99
</brackets-left>
1010

1111
<!-- data 为对象时, index 表示 key, 为数组才表示索引 -->
@@ -20,6 +20,7 @@
2020
@click.stop="handleClick">
2121
<tree
2222
v-if="Array.isArray(item) || isObject(item)"
23+
:json="data"
2324
:data="item"
2425
:path="path + (Array.isArray(data) ? `[${index}]` : `.${index}`)"
2526
:index="index"
@@ -50,12 +51,16 @@
5051
export default {
5152
name: 'tree',
5253
props: {
53-
data: {},
54-
child: Boolean,
54+
/* 外部可用 START */
55+
data: {}, // 当前树的数据
56+
// 数据层级顶级路径
5557
path: {
5658
type: String,
5759
default: 'root'
5860
},
61+
/* 外部可用 END */
62+
json: {}, // 当前树的父级数据
63+
child: Boolean, // 是否子树
5964
index: {},
6065
lastIndex: {}
6166
},

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import VueJsonPretty from './components/tree.vue'
22

33
export default Object.assign({}, VueJsonPretty, {
4-
version: '1.1.0'
4+
version: '1.1.1'
55
})

0 commit comments

Comments
 (0)