gpt4 book ai didi

javascript - TipTap 编辑器中无法正确识别空格

转载 作者:行者123 更新时间:2023-12-03 06:42:57 25 4
gpt4 key购买 nike

我们在项目中使用了 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触发,但更改了 watch ,使其仅调用 editor.setContent当值实际上不同时。

  watch: {
value() {
let html = this.editor.getHTML();
if (html !== this.value) {
this.editor.setContent(this.value);
}
},
},

关于javascript - TipTap 编辑器中无法正确识别空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61752404/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com