使用 Tiptap 编辑器的基本版本:
<template>
<div v-if="editor">
<editor-content :editor="editor" />
</div>
</template>
<script>
import { Editor, EditorContent } from '@tiptap/vue-3'
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
export default {
components: {
EditorContent,
},
data() {
return {
editor: null,
}
},
mounted() {
this.editor = new Editor({
extensions: [
Document,
Paragraph,
Text,
],
content: `
<p>The Paragraph extension is not required, but it’s very likely you want to use it. It’s needed to write paragraphs of text. </p>
`,
})
},
beforeUnmount() {
this.editor.destroy()
},
}
</script>
(可在https://tiptap.dev/api/nodes/paragraph进行测试)
我注意到在粘贴多行文本时,例如:
Hello
This is a test with two break lines at the above and three after this:
Thanks!
<p>Hello</p>
<p>This is a test with two break lines at the above and three after this:</p>
<p>Thanks!</p>
在这种情况下,所有“多个”断线都已被删除!
有没有办法保留它们,这意味着一旦执行粘贴,内容应该是:
<p>Hello</p>
<p></p>
<p></p>
<p>This is a test with two break lines at the above and three after this:</p>
<p></p>
<p></p>
<p></p>
<p>Thanks!</p>
(我也可以使用 Hardbreak 扩展<p><br /></p>
而不是<p></p>
启用 Hardbreak 扩展,但无论哪种情况,它都不起作用)。