fix(editor): 富文本编辑器初始化 race 导致正文不显示
useEditor 异步创建 vs loadItem 异步加载的 race condition: - mount 时 useEditor 用 props.modelValue='' 初始化 - watch modelValue 触发时 editor.value 还是 null 被跳过 - editor 实例化后 watch 不会再跑,最终内容为空 修复:增加 watch editor 实例的逻辑,编辑器创建后立即同步当前 modelValue。 影响范围:articles/[id]、blogs/[id] 编辑页(共用同一组件)。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
这个提交包含在:
父节点
14935dfbf4
当前提交
3ca8af262e
@ -74,6 +74,14 @@ watch(() => props.modelValue, (val) => {
|
|||||||
if (val !== current) editor.value.commands.setContent(val || '', false)
|
if (val !== current) editor.value.commands.setContent(val || '', false)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// editor 实例异步创建,若先于 modelValue 异步加载完成, watch modelValue 时 editor 还是 null 会跳过, 导致内容空白
|
||||||
|
watch(editor, (ed) => {
|
||||||
|
if (!ed) return
|
||||||
|
if (props.modelValue && ed.getHTML() !== props.modelValue) {
|
||||||
|
ed.commands.setContent(props.modelValue, false)
|
||||||
|
}
|
||||||
|
}, { immediate: true })
|
||||||
|
|
||||||
onBeforeUnmount(() => editor.value?.destroy())
|
onBeforeUnmount(() => editor.value?.destroy())
|
||||||
|
|
||||||
function btn(active) { return { 'toolbar-btn': true, active } }
|
function btn(active) { return { 'toolbar-btn': true, active } }
|
||||||
|
|||||||
正在加载...
x
在新工单中引用
屏蔽一个用户