1
1
<template >
2
2
<div class =" example" >
3
3
<div class =" example-box" >
4
- <h2 class =" title" >EXAMPLE 1</h2 >
4
+ <h2 class =" title" >
5
+ EXAMPLE 1
6
+ </h2 >
5
7
<div class =" block" >
6
8
<h3 >JSON:</h3 >
7
- <textarea v-model =" val" ></ textarea >
9
+ <textarea v-model =" val" / >
8
10
9
11
<h3 >Options:</h3 >
10
12
<div class =" options" >
11
13
<div >
12
14
<label >showLength</label >
13
- <input type =" checkbox" v-model =" showLength" >
15
+ <input
16
+ v-model =" showLength"
17
+ type =" checkbox"
18
+ >
14
19
</div >
15
20
<div >
16
21
<label >showLine</label >
17
- <input type =" checkbox" v-model =" showLine" >
22
+ <input
23
+ v-model =" showLine"
24
+ type =" checkbox"
25
+ >
18
26
</div >
19
27
<div >
20
28
<label >showDoubleQuotes</label >
21
- <input type =" checkbox" v-model =" showDoubleQuotes" >
29
+ <input
30
+ v-model =" showDoubleQuotes"
31
+ type =" checkbox"
32
+ >
22
33
</div >
23
34
<div >
24
35
<label >highlightMouseoverNode</label >
25
- <input type =" checkbox" v-model =" highlightMouseoverNode" >
36
+ <input
37
+ v-model =" highlightMouseoverNode"
38
+ type =" checkbox"
39
+ >
26
40
</div >
27
41
<div >
28
42
<label >collapsedOnClickBrackets</label >
29
- <input type =" checkbox" v-model =" collapsedOnClickBrackets" >
43
+ <input
44
+ v-model =" collapsedOnClickBrackets"
45
+ type =" checkbox"
46
+ >
30
47
</div >
31
48
<div >
32
49
<label >use custom formatter</label >
33
- <input type =" checkbox" v-model =" useCustomLinkFormatter" >
50
+ <input
51
+ v-model =" useCustomLinkFormatter"
52
+ type =" checkbox"
53
+ >
34
54
</div >
35
55
<div >
36
56
<label >deep</label >
37
57
<select v-model =" deep" >
38
- <option :value =" 2" >2</option >
39
- <option :value =" 3" >3</option >
40
- <option :value =" 4" >4</option >
58
+ <option :value =" 2" >
59
+ 2
60
+ </option >
61
+ <option :value =" 3" >
62
+ 3
63
+ </option >
64
+ <option :value =" 4" >
65
+ 4
66
+ </option >
41
67
</select >
42
68
</div >
43
69
</div >
53
79
:highlight-mouseover-node =" highlightMouseoverNode"
54
80
:collapsed-on-click-brackets =" collapsedOnClickBrackets"
55
81
:custom-value-formatter =" useCustomLinkFormatter ? customLinkFormatter : null"
56
- @click =" handleClick" >
57
- </ vue-json-pretty >
82
+ @click =" handleClick"
83
+ / >
58
84
</div >
59
85
</div >
60
86
61
87
<div class =" example-box" >
62
- <h2 class =" title" >EXAMPLE 2</h2 >
88
+ <h2 class =" title" >
89
+ EXAMPLE 2
90
+ </h2 >
63
91
<div class =" block" >
64
92
<h3 >JSON:</h3 >
65
- <textarea v-model =" val" ></ textarea >
93
+ <textarea v-model =" val" / >
66
94
67
95
<h3 >Options:</h3 >
68
96
<div class =" options" >
69
97
<div >
70
98
<label >selectableType</label >
71
99
<select v-model =" selectableType" >
72
- <option label =" -" ></ option >
100
+ <option label =" -" / >
73
101
<option >single</option >
74
102
<option >multiple</option >
75
103
</select >
76
104
</div >
77
105
<div >
78
106
<label >showSelectController</label >
79
- <input type =" checkbox" v-model =" showSelectController" >
107
+ <input
108
+ v-model =" showSelectController"
109
+ type =" checkbox"
110
+ >
80
111
</div >
81
112
<div >
82
113
<label >selectOnClickNode</label >
83
- <input type =" checkbox" v-model =" selectOnClickNode" >
114
+ <input
115
+ v-model =" selectOnClickNode"
116
+ type =" checkbox"
117
+ >
84
118
</div >
85
119
<div >
86
120
<label >path</label >
87
- <input type =" text" v-model =" path" >
121
+ <input
122
+ v-model =" path"
123
+ type =" text"
124
+ >
88
125
</div >
89
126
<div >
90
127
<label >showLength</label >
91
- <input type =" checkbox" v-model =" showLength" >
128
+ <input
129
+ v-model =" showLength"
130
+ type =" checkbox"
131
+ >
92
132
</div >
93
133
<div >
94
134
<label >showLine</label >
95
- <input type =" checkbox" v-model =" showLine" >
135
+ <input
136
+ v-model =" showLine"
137
+ type =" checkbox"
138
+ >
96
139
</div >
97
140
<div >
98
141
<label >showDoubleQuotes</label >
99
- <input type =" checkbox" v-model =" showDoubleQuotes" >
142
+ <input
143
+ v-model =" showDoubleQuotes"
144
+ type =" checkbox"
145
+ >
100
146
</div >
101
147
<div >
102
148
<label >highlightMouseoverNode</label >
103
- <input type =" checkbox" v-model =" highlightMouseoverNode" >
149
+ <input
150
+ v-model =" highlightMouseoverNode"
151
+ type =" checkbox"
152
+ >
104
153
</div >
105
154
<div >
106
155
<label >highlightSelectedNode</label >
107
- <input type =" checkbox" v-model =" highlightSelectedNode" >
156
+ <input
157
+ v-model =" highlightSelectedNode"
158
+ type =" checkbox"
159
+ >
108
160
</div >
109
161
<div >
110
162
<label >collapsedOnClickBrackets</label >
111
- <input type =" checkbox" v-model =" collapsedOnClickBrackets" >
163
+ <input
164
+ v-model =" collapsedOnClickBrackets"
165
+ type =" checkbox"
166
+ >
112
167
</div >
113
168
<div >
114
169
<label >deep</label >
115
170
<select v-model =" deep" >
116
- <option :value =" 2" >2</option >
117
- <option :value =" 3" >3</option >
118
- <option :value =" 4" >4</option >
171
+ <option :value =" 2" >
172
+ 2
173
+ </option >
174
+ <option :value =" 3" >
175
+ 3
176
+ </option >
177
+ <option :value =" 4" >
178
+ 4
179
+ </option >
119
180
</select >
120
181
</div >
121
182
<div >
122
183
<label >use custom formatter</label >
123
- <input type =" checkbox" v-model =" useCustomLinkFormatter" >
184
+ <input
185
+ v-model =" useCustomLinkFormatter"
186
+ type =" checkbox"
187
+ >
124
188
</div >
125
189
</div >
126
190
<h3 >v-model:</h3 >
127
- <div >{{value}}</div >
191
+ <div >{{ value }}</div >
128
192
<h3 >Current Click:</h3 >
129
- <div >path: {{itemPath}}</div >
130
- <div >data: <pre >{{itemData}}</pre ></div >
193
+ <div >path: {{ itemPath }}</div >
194
+ <div >data: <pre >{{ itemData }}</pre ></div >
131
195
</div >
132
196
<div class =" block" >
133
197
<h3 >vue-json-pretty:</h3 >
134
198
<vue-json-pretty
135
199
v-if =" renderOK"
200
+ v-model =" value"
136
201
:data =" json"
137
202
:path =" path"
138
203
:deep =" deep"
143
208
:show-line =" showLine"
144
209
:select-on-click-node =" selectOnClickNode"
145
210
:collapsed-on-click-brackets =" collapsedOnClickBrackets"
146
- v-model =" value"
147
211
:path-selectable =" ((path, data) => typeof data !== 'number')"
148
212
:selectable-type =" selectableType"
149
213
:show-select-controller =" showSelectController"
150
214
:custom-value-formatter =" useCustomLinkFormatter ? customLinkFormatter : null"
151
215
@click =" handleClick(...arguments, 'complexTree')"
152
- @change =" handleChange" >
153
- </ vue-json-pretty >
216
+ @change =" handleChange"
217
+ / >
154
218
</div >
155
219
</div >
156
- <a style =" position : fixed ; right : 0 ; top : 0 ;" href =" https://github.com/leezng/vue-json-pretty" target =" _blank" ><img style =" position : absolute ; top : 0 ; right : 0 ; border : 0 ;" src =" https://camo.githubusercontent.com/652c5b9acfaddf3a9c326fa6bde407b87f7be0f4/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6f72616e67655f6666373630302e706e67" alt =" Fork me on GitHub" data-canonical-src =" https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png" ></a >
220
+ <a
221
+ style =" position : fixed ; right : 0 ; top : 0 ;"
222
+ href =" https://github.com/leezng/vue-json-pretty"
223
+ target =" _blank"
224
+ ><img
225
+ style =" position : absolute ; top : 0 ; right : 0 ; border : 0 ;"
226
+ src =" https://camo.githubusercontent.com/652c5b9acfaddf3a9c326fa6bde407b87f7be0f4/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6f72616e67655f6666373630302e706e67"
227
+ alt =" Fork me on GitHub"
228
+ data-canonical-src =" https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png"
229
+ ></a >
157
230
</div >
158
231
</template >
159
232
160
233
<script >
161
234
import VueJsonPretty from ' src'
162
235
163
236
export default {
164
- name: ' app ' ,
237
+ name: ' App ' ,
165
238
components: {
166
239
VueJsonPretty
167
240
},
@@ -202,13 +275,17 @@ export default {
202
275
path: ' res' ,
203
276
deep: 3 ,
204
277
itemData: {},
205
- itemPath: ' '
278
+ itemPath: ' ' ,
279
+ json: {},
206
280
}
207
281
},
208
- created () {
209
- this .val = JSON .stringify (this .data )
210
- },
211
282
watch: {
283
+ val (newVal ) {
284
+ try {
285
+ this .json = JSON .parse (this .val )
286
+ } catch (err) {
287
+ }
288
+ },
212
289
selectableType (newVal ) {
213
290
this .renderOK = false
214
291
if (newVal === ' single' ) {
@@ -222,15 +299,8 @@ export default {
222
299
})
223
300
}
224
301
},
225
- computed: {
226
- json () {
227
- try {
228
- this .cache = JSON .parse (this .val )
229
- return this .cache
230
- } catch (err) {
231
- return this .cache || this .data
232
- }
233
- }
302
+ created () {
303
+ this .val = JSON .stringify (this .data )
234
304
},
235
305
methods: {
236
306
handleClick (path , data , treeName = ' ' ) {
0 commit comments