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>
这个提交包含在:
wx 2026-05-09 09:14:25 +08:00
父节点 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 } }