update the JSON editor to return a normal JSON object

This commit is contained in:
Michael Genson 2025-06-18 19:33:59 +00:00
commit 6ce9f66693

View file

@ -1,27 +1,51 @@
<template> <template>
<JsonEditorVue <JsonEditorVue
v-model="modelValue" :modelValue="modelValue"
v-bind="$attrs" v-bind="$attrs"
:style="{ height }" :style="{ height }"
@input="$emit('update:modelValue', $event)" :stringified="false"
@change="onChange"
/> />
</template> </template>
<script lang="ts"> <script setup lang="ts">
import { defineProps, defineEmits } from 'vue'
import JsonEditorVue from 'json-editor-vue' import JsonEditorVue from 'json-editor-vue'
export default defineNuxtComponent({ const props = defineProps({
components: { JsonEditorVue },
props: {
modelValue: { modelValue: {
type: Object, type: Object,
default: () => ({}), default: () => ({}),
}, },
height: { height: {
type: String, type: String,
default: "1500px", default: '1500px',
}, },
}, })
emits: ["update:modelValue"],
}); const emit = defineEmits(['update:modelValue'])
function parseEvent(event: any): object {
if (!event) {
return {};
}
try {
if (event.json) {
return event.json;
}
else if (event.text) {
return JSON.parse(event.text);
}
else {
return event;
}
} catch {
return {};
}
}
function onChange(event: any) {
emit('update:modelValue', parseEvent(event));
}
</script> </script>