forked from leezng/vue-json-pretty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEditable.vue
117 lines (113 loc) · 2.69 KB
/
Editable.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<template>
<div class="example-box">
<div class="block">
<h3>JSON:</h3>
<textarea v-model="val" />
<h3>Options:</h3>
<div class="options">
<div>
<label>showLine</label>
<input v-model="showLine" type="checkbox" />
</div>
<div>
<label>showLineNumber</label>
<input v-model="showLineNumber" type="checkbox" />
</div>
<div>
<label>editable</label>
<input v-model="editable" type="checkbox" />
</div>
<div>
<label>editableTrigger</label>
<select v-model="editableTrigger">
<option value="click">click</option>
<option value="dblclick">dblclick</option>
</select>
</div>
<div>
<label>deep</label>
<select v-model="deep">
<option :value="2">2</option>
<option :value="3">3</option>
<option :value="4">4</option>
</select>
</div>
</div>
</div>
<div class="block">
<h3>vue-json-pretty:</h3>
<vue-json-pretty
v-model="data"
:deep="deep"
:show-double-quotes="true"
:show-line="showLine"
:show-line-number="showLineNumber"
:editable="editable"
:editable-trigger="editableTrigger"
/>
</div>
</div>
</template>
<script>
import VueJsonPretty from 'src';
const defaultData = {
status: 200,
text: '',
error: null,
config: undefined,
data: [
{
news_id: 51184,
title: 'iPhone X Review: Innovative future with real black technology',
source: 'Netease phone',
},
{
news_id: 51183,
title:
'Traffic paradise: How to design streets for people and unmanned vehicles in the future?',
source: 'Netease smart',
link: 'http://netease.smart/traffic-paradise/1235',
},
{
news_id: 51182,
title:
"Teslamask's American Business Relations: The government does not pay billions to build factories",
source: 'AI Finance',
members: ['Daniel', 'Mike', 'John'],
},
],
};
export default {
name: 'Editable',
components: {
VueJsonPretty,
},
data() {
return {
val: JSON.stringify(defaultData),
data: defaultData,
showLine: true,
showLineNumber: false,
editable: true,
editableTrigger: 'click',
deep: 3,
};
},
watch: {
val(newVal) {
try {
this.data = JSON.parse(newVal);
} catch (err) {
console.log('JSON ERROR');
}
},
data(newVal) {
try {
this.val = JSON.stringify(newVal);
} catch (err) {
console.log('JSON ERROR');
}
},
},
};
</script>