From b82c2ecda7a1d7d546430f1dbf5a8fd2341dbe5b Mon Sep 17 00:00:00 2001 From: JiangQiming <291854119@qq.com> Date: Mon, 20 Feb 2023 16:54:17 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E4=BB=A3=E7=A0=81=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=99=A8=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/MonacoEditor/index.vue | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/components/MonacoEditor/index.vue b/src/components/MonacoEditor/index.vue index 6762be92..7a22d6b7 100644 --- a/src/components/MonacoEditor/index.vue +++ b/src/components/MonacoEditor/index.vue @@ -59,6 +59,20 @@ onMounted(() => { emit('update:modelValue', value); }); }); + +/** + * 代码格式化 + */ +const editorFormat = () => { + if (!instance) return; + instance.getAction('editor.action.formatDocument')?.run(); +}; + +watchEffect(() => { + setTimeout(() => { + editorFormat(); + }, 300); +});