【发布时间】:2020-08-28 08:01:08
【问题描述】:
我们在项目中使用了 TipTap 的富文本编辑器。
但是我们有一个问题,即不能正确识别空间,并且只有在每 2 次单击后才会创建一个空间。我们使用 Vue.JS 作为框架。
import { Editor, EditorContent, EditorMenuBar } from 'tiptap'
import {
HardBreak,
Heading,
OrderedList,
BulletList,
ListItem,
Bold,
Italic,
History
} from 'tiptap-extensions'
import EditorMenuButton from './EditorMenuButton.vue'
export default {
name: 'editor',
components: {
EditorMenuButton,
EditorMenuBar,
EditorContent
},
props: {
value: {
type: null,
default: ' '
}
},
data () {
return {
innerValue: ' ',
editor: new Editor({
extensions: [
new HardBreak(),
new Heading({ levels: [1, 2, 3] }),
new BulletList(),
new OrderedList(),
new ListItem(),
new Bold(),
new Italic(),
new History()
],
content: `${this.innerValue}`,
onUpdate: ({ getHTML }) => {
this.innerValue = getHTML()
}
})
}
},
watch: {
// Handles internal model changes.
innerValue (newVal) {
this.$emit('input', newVal)
},
// Handles external model changes.
value (newVal) {
this.innerValue = newVal
this.editor.setContent(this.innerValue)
}
},
mounted () {
if (this.value) {
this.innerValue = this.value
this.editor.setContent(this.innerValue)
}
},
beforeDestroy () {
this.editor.destroy()
}
}
</script>
有没有人知道假设每两个空格的原因是什么?
【问题讨论】:
-
在没有minimal reproducible example(实际上再现行为)的情况下获得有用答案的机会接近
null。使用 codesandbox.io 或任何其他基于在线多文件节点的编辑器。您在此处显示的内容不会重现所描述的行为并且缺少:EditorMenuButton.vue的模板和内容(很可能是您的错误来自哪里)。 -
Here's a sandbox 与您到目前为止所展示的内容。如您所见,它按预期工作。因此,请向其中添加错误,以便有人可以调试它。 :) 注意:我确实做了一些更改,因为您无法在
data中初始化编辑器。在mounted中执行此操作,如他们的示例中所示。 Here's why. -
谢谢我们会尝试在代码沙箱中编程
-
@tao 在
data中初始化编辑器正是examples 中的写法。 -
@Erich,与链接示例的显着区别在于它没有在
data中使用this。因为它不可用。这就是为什么我建议将其移至mounted。
标签: javascript html vue.js frontend tiptap