Slate 在 Vue 中如何正确绑定编辑器内容?
我在用 Slate 做富文本编辑器,但和 Vue 的响应式数据绑定总是出问题。明明改了 editor.children,视图却没更新,是不是我哪里写错了?
试过直接赋值、用 Vue.set,甚至强制刷新组件,都没用。控制台也没报错,就是不渲染新内容。
<template>
<div ref="editorRef" />
</template>
<script setup>
import { onMounted, ref } from 'vue'
import { createEditor } from 'slate'
import { withHistory } from 'slate-history'
import { Slate, Editable, withReact } from 'slate-react'
const editorRef = ref(null)
const editor = withHistory(withReact(createEditor()))
onMounted(() => {
editor.children = [{ type: 'paragraph', children: [{ text: '初始内容' }] }]
})
</script>
暂无解答