fix(editor): sync wangEditor content on async model updates

This commit is contained in:
Ray.Hao
2026-01-30 08:06:26 +08:00
parent da7163f463
commit 757ac7931c

View File

@@ -76,8 +76,24 @@ const editorConfig = ref<Partial<IEditorConfig>>({
// 记录 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;