|
@@ -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(() => {
|