jsonEditor.vue
1.01 KB
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
<template>
<div ref="jsoneditorRef" style="height: 100%; width: 100%"></div>
</template>
<script lang="ts" setup>
import { ref, onMounted, nextTick, unref } from 'vue';
import jsoneditor from 'jsoneditor';
import 'jsoneditor/dist/jsoneditor.min.css';
// json 以及初始化JSON
const jsoneditorRef = ref();
const jsonValue = ref({});
const jsonInstance = ref();
onMounted(() => {
nextTick(() => {
let options = {
mode: 'code',
mainMenuBar: false,
statusBar: false,
};
let editor = new jsoneditor(jsoneditorRef.value, options);
editor.set(jsonValue.value);
jsonInstance.value = editor;
});
});
const getJsonValue = () => unref(jsonInstance).get();
const setJsonValue = (Json) => {
nextTick(() => {
unref(jsonInstance).set(Json);
});
};
defineExpose({
getJsonValue,
setJsonValue,
jsonInstance,
});
</script>
<style>
.jsoneditor {
border: none;
}
</style>