fix JsonEditor.vue

This commit is contained in:
long2ice
2020-04-30 22:17:55 +08:00
parent ea5b91e4df
commit 16f188860a
2 changed files with 30 additions and 27 deletions

View File

@@ -132,10 +132,11 @@
</div>
<div v-else-if="['json'].includes(field.type)">
<b-json-editor
v-if="model"
v-bind="field"
v-model="model"
:value="model"
@input="model = arguments[0]"
:options="{modes:['tree','view','form','code','text','preview']}"
:options="{modes:['tree','view','form','code','text','preview'],language:currentLanguage}"
ref="editor"/>
</div>
<div v-else-if="field.fields">
@@ -437,7 +438,7 @@
this.field.is_array ||
this.field.type == "array" ||
this.field.is_table;
const isObject = this.field.type == "object";
const isObject = this.field.type == "object" || this.field.type == "json";
let ret = this.value;
if (!this.value) {
if (isArray) {

View File

@@ -2,29 +2,31 @@
<div ref="editor"></div>
</template>
<script>
import 'jsoneditor/dist/jsoneditor.min.css'
import JSONEditor from "jsoneditor";
export default {
name: "b-json-editor",
props: {
value: null,
options: {}
},
data() {
return {
editor: null
};
},
mounted() {
this.editor = new JSONEditor(this.$refs.editor, this.options);
if (typeof this.value === "string") {
this.value = JSON.parse(this.value);
import 'jsoneditor/dist/jsoneditor.min.css'
import JSONEditor from "jsoneditor";
export default {
name: "b-json-editor",
props: {
value: null,
options: {}
},
data() {
return {
editor: null
};
},
mounted() {
this.options.onChange = () => {
this.$emit("input", this.editor.get());
}
this.editor = new JSONEditor(this.$refs.editor, this.options);
if (typeof this.value === "string") {
this.value = JSON.parse(this.value);
}
this.editor.set(this.value || {});
},
created() {
}
this.editor.set(this.value || {});
this.editor._onChange = v => {
this.$emit("input", this.editor.get());
}
},
created() {}
};
};
</script>