-
Notifications
You must be signed in to change notification settings - Fork 702
/
Copy pathjson_editor.vue
64 lines (62 loc) · 1.41 KB
/
json_editor.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
<template>
<div class="json_editor">
<div ref="jsonEditor" class="jsonEditor"></div>
<button class="nya-btn mt-15" @click="download">
下载 JSON 文件
</button>
</div>
</template>
<script>
import 'jsoneditor/dist/jsoneditor.min.css';
import createFile from '~/utils/createFile.js';
let JSONEditor;
if (process.browser) {
JSONEditor = require('jsoneditor');
}
export default {
name: 'JsonEditor',
head() {
return this.$store.state.currentTool.head;
},
data() {
return {
JSONEditor: null
};
},
mounted() {
this.init();
},
methods: {
init() {
this.JSONEditor = new JSONEditor(
this.$refs.jsonEditor,
{
mode: 'code',
modes: ['text', 'code', 'tree', 'form', 'view']
},
{
Array: [1, 2, 3],
Boolean: true,
Null: null,
Number: 123,
Object: { a: 'b', c: 'd' },
String: 'Hello World'
}
);
},
download() {
createFile(this.JSONEditor.getText(), 'main.json');
}
}
};
</script>
<style lang="scss">
.json_editor {
.jsonEditor {
height: 600px;
}
.nya-btn {
margin-top: 15px;
}
}
</style>