Skip to content

Commit 0671124

Browse files
committed
refactor: Example code pretty.
1 parent 1c5d1b1 commit 0671124

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

example/App.vue

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
<div class="block">
7272
<h3>vue-json-pretty:</h3>
7373
<vue-json-pretty
74-
:data="json"
74+
:data="data"
7575
:deep="deep"
7676
:show-double-quotes="showDoubleQuotes"
7777
:show-length="showLength"
@@ -198,7 +198,7 @@
198198
<vue-json-pretty
199199
v-if="renderOK"
200200
v-model="value"
201-
:data="json"
201+
:data="data"
202202
:path="path"
203203
:deep="deep"
204204
:show-double-quotes="showDoubleQuotes"
@@ -233,6 +233,26 @@
233233
<script>
234234
import VueJsonPretty from 'src'
235235
236+
const defaultData = {
237+
status: 200,
238+
error: '',
239+
data: [{
240+
news_id: 51184,
241+
title: 'iPhone X Review: Innovative future with real black technology',
242+
source: 'Netease phone'
243+
}, {
244+
news_id: 51183,
245+
title: 'Traffic paradise: How to design streets for people and unmanned vehicles in the future?',
246+
source: 'Netease smart',
247+
link: 'http://netease.smart/traffic-paradise/1235'
248+
}, {
249+
news_id: 51182,
250+
title: 'Teslamask\'s American Business Relations: The government does not pay billions to build factories',
251+
source: 'AI Finance',
252+
members: ['Daniel', 'Mike', 'John']
253+
}]
254+
}
255+
236256
export default {
237257
name: 'App',
238258
components: {
@@ -241,26 +261,8 @@ export default {
241261
data () {
242262
return {
243263
renderOK: true,
244-
val: '',
245-
data: {
246-
status: 200,
247-
error: '',
248-
data: [{
249-
news_id: 51184,
250-
title: 'iPhone X Review: Innovative future with real black technology',
251-
source: 'Netease phone'
252-
}, {
253-
news_id: 51183,
254-
title: 'Traffic paradise: How to design streets for people and unmanned vehicles in the future?',
255-
source: 'Netease smart',
256-
link: 'http://netease.smart/traffic-paradise/1235'
257-
}, {
258-
news_id: 51182,
259-
title: 'Teslamask\'s American Business Relations: The government does not pay billions to build factories',
260-
source: 'AI Finance',
261-
members: ['Daniel', 'Mike', 'John']
262-
}]
263-
},
264+
val: JSON.stringify(defaultData),
265+
data: defaultData,
264266
value: 'res.error',
265267
selectableType: 'single',
266268
showSelectController: true,
@@ -276,13 +278,12 @@ export default {
276278
deep: 3,
277279
itemData: {},
278280
itemPath: '',
279-
json: {},
280281
}
281282
},
282283
watch: {
283284
val(newVal) {
284285
try {
285-
this.json = JSON.parse(this.val)
286+
this.data = JSON.parse(this.val)
286287
} catch (err) {
287288
console.log('JSON ERROR')
288289
}
@@ -300,9 +301,6 @@ export default {
300301
})
301302
}
302303
},
303-
created () {
304-
this.val = JSON.stringify(this.data)
305-
},
306304
methods: {
307305
handleClick (path, data, treeName = '') {
308306
console.log('click: ', path, data, treeName)

0 commit comments

Comments
 (0)