kailong321200875 / vue-element-plus-admin

A backend management system based on vue3, typescript, element-plus, and vite
https://element-plus-admin.cn/
MIT License
2.81k stars 682 forks source link

fix: 修复富文本编辑器初始化时, 报错 Error: Cannot find a descendant at path [0,1] i… #472

Closed clddup closed 5 months ago

clddup commented 5 months ago

富文本html.txt

当html内容为上面文件里的内容时, 会报错

image

排查发现在组件 watch 配置 immediate: true时 刚进来就给 valueHtml 赋值上面文本内容会报错

watch(
  () => props.modelValue,
  (val: string) => {
    if (val === unref(valueHtml)) return
    valueHtml.value = val 
  },
  {
    immediate: true
  }
)

解决办法: 应该将 valueHtml 初始化赋值放到 handleCreated 函数中, 并将 immediate去掉

watch(
  () => props.modelValue,
  (val: string) => {
    if (val === unref(valueHtml)) return
    valueHtml.value = val 
  }
)
```js
const handleCreated = (editor: IDomEditor) => {
  editorRef.value = editor
  valueHtml.value = props.modelValue
}