fix(editor): code-editor组件json类型序列化出错

This commit is contained in:
roymondchen 2023-07-03 14:57:31 +08:00
parent 5b3c700f00
commit 2d4a6aa22a

View File

@ -37,10 +37,14 @@ const emit = defineEmits(['initd', 'save']);
const toString = (v: string | any, language: string): string => {
let value = '';
if (typeof v !== 'string') {
if (props.language.toLocaleLowerCase() === 'json') {
value = JSON.stringify(v, null, 2);
} else {
value = serialize(v, {
space: 2,
unsafe: true,
}).replace(/"(\w+)":\s/g, '$1: ');
}
} else {
value = v;
}