Skip to content

Commit

Permalink
fix(editor): code-editor组件json类型序列化出错
Browse files Browse the repository at this point in the history
  • Loading branch information
roymondchen committed Jul 3, 2023
1 parent 5b3c700 commit 2d4a6aa
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/editor/src/layouts/CodeEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ const emit = defineEmits(['initd', 'save']);
const toString = (v: string | any, language: string): string => {
let value = '';
if (typeof v !== 'string') {
value = serialize(v, {
space: 2,
unsafe: true,
}).replace(/"(\w+)":\s/g, '$1: ');
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;
}
Expand Down

0 comments on commit 2d4a6aa

Please sign in to comment.