fix(editor): sync wangEditor content on async model updates
This commit is contained in:
@@ -76,8 +76,24 @@ const editorConfig = ref<Partial<IEditorConfig>>({
|
|||||||
// 记录 editor 实例,重要!
|
// 记录 editor 实例,重要!
|
||||||
const handleCreated = (editor: any) => {
|
const handleCreated = (editor: any) => {
|
||||||
editorRef.value = editor;
|
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(() => {
|
onBeforeUnmount(() => {
|
||||||
const editor = editorRef.value;
|
const editor = editorRef.value;
|
||||||
|
|||||||
Reference in New Issue
Block a user