From 30384e0b6ad5138c4d83c9bb1390abc6065efe80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=9E=E4=BB=99=E9=83=BD=E6=B2=A1=E7=94=A8?= <615206459@qq.com> Date: Wed, 18 Oct 2023 14:41:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/extend/editor/monaco/index.vue | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/modules/extend/editor/monaco/index.vue b/src/modules/extend/editor/monaco/index.vue index f7b2647..5cf62a4 100644 --- a/src/modules/extend/editor/monaco/index.vue +++ b/src/modules/extend/editor/monaco/index.vue @@ -19,7 +19,7 @@ import { useFormat } from "./format"; import { parsePx } from "/@/cool/utils"; import { useTypes } from "./types"; import { useCool } from "/@/cool"; -import { merge } from "lodash-es"; +import { isObject, merge } from "lodash-es"; const props = defineProps({ modelValue: String, @@ -61,10 +61,14 @@ function getContent() { } // 设置内容 -function setContent(value?: string) { - if (value != getContent()) { - editor?.setValue(value || ""); +function setContent(value: string = "") { + if (isObject(value)) { + value = JSON.stringify(value); + } else { + value = value.toString(); } + + editor?.setValue(value); } // 格式化内容 @@ -74,7 +78,7 @@ async function formatCode() { } // 创建编辑器 -function init() { +function create() { const options = merge( { theme: "default", @@ -148,7 +152,7 @@ watch( ); onMounted(() => { - init(); + create(); }); onUnmounted(() => {