From 757ac7931cdf4d497165bfe88ba3d01faa615ffa Mon Sep 17 00:00:00 2001 From: "Ray.Hao" <1490493387@qq.com> Date: Fri, 30 Jan 2026 08:06:26 +0800 Subject: [PATCH] fix(editor): sync wangEditor content on async model updates --- src/components/WangEditor/index.vue | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/components/WangEditor/index.vue b/src/components/WangEditor/index.vue index 68d39dab..cea0258d 100644 --- a/src/components/WangEditor/index.vue +++ b/src/components/WangEditor/index.vue @@ -76,8 +76,24 @@ const editorConfig = ref>({ // 记录 editor 实例,重要! const handleCreated = (editor: any) => { editorRef.value = editor; + const value = modelValue.value ?? ""; + if (value) { + editor.setHtml(value); + } }; +watch( + () => modelValue.value, + (value) => { + const editor = editorRef.value; + if (!editor) return; + const nextValue = value ?? ""; + if (nextValue !== editor.getHtml()) { + editor.setHtml(nextValue); + } + } +); + // 组件销毁时,也及时销毁编辑器,重要! onBeforeUnmount(() => { const editor = editorRef.value;