javascript - TipTap 编辑器中无法正确识别空格
问题描述
我们在项目中使用了 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>
有谁知道假设每两个空格的原因是什么?
解决方案
我们遇到了同样的问题,我们保留了onUpdate
触发器但更改了手表,以便它只会editor.setContent
在值实际不同时调用。
watch: {
value() {
let html = this.editor.getHTML();
if (html !== this.value) {
this.editor.setContent(this.value);
}
},
},
推荐阅读
- python - 如何在 app.run() 之后销毁 pygubu 窗口?
- javascript - 模拟文件中的间谍功能
- c++ - 如何将旧的 z3::expr(Oldvec) 更改为新的 z3::expr(Vec)?
- ios - Xamarin/Cosmos DB 设计问题 服务中介与否?(设计问题)
- python - Beautiful Soup Selector 返回一个空列表
- sql-server - 大表上的 SQL Server 或实体框架外连接查询
- c++ - 创建带参数的字符串 c++ | 格式化 c++20
- laravel - 如何使用 laravel / lumen 将变量传递给路由文件?
- python - 有没有办法在不获取嵌套值的情况下递归调用函数的多个可变数量的分支?
- android - 如何删除扬声器的噪音级别?