I'm using the Tiptap editor and I have issues accessing the content of the editor.
I need to post the content of the editor to an API so I need the content. Here is my code:
import tippy from "tippy.js";
import { Editor, EditorContent, VueRenderer } from "@tiptap/vue-2";
import Document from "@tiptap/extension-document";
import Paragraph from "@tiptap/extension-paragraph";
import Text from "@tiptap/extension-text";
export default {
components: {
EditorContent
},
props: {
comment_type: String,
comment_text: String,
comment_id: Number,
edit_mode: Boolean
},
data() {
return {
editor: null,
limit: 280,
users: [],
comment_da: {},
edit_comment_da: {}
};
},
watch: {
comment_text(value) {
console.log(value);
this.editor.setContent(value);
}
},
mounted() {
const self = this;
const CustomParagraph = Paragraph.extend({
addKeyboardShortcuts() {
return {
// ↓ your new keyboard shortcut
"Shift-Enter": () => self.addComment()
};
}
});
this.editor = new Editor({
extensions: [
Document,
CustomParagraph,
Text,
],
content: this.comment_text
});
},
beforeDestroy() {
this.editor.destroy();
},
}
<template>
<div>
<editor-content :editor="editor" class="form-control"/>
</div>
</template>
In the parent component I have some properties which I need to pass to the Tiptap editor:
import editor from "./components/editor";
new Vue({
components: {
editor
},
data() {
comment_da: {},
comment_text: "",
}
})
<div class="m-messenger__form-controls">
<editor
v-model="comment_text"
:comment_text="comment_text"
:comment_type="'comment'"
:comment_id="comment_da.id"
/>
</div>
I cannot access the editor content. I've tried this solution but I'm getting this error constantly while typing in it:
Error: "getHTML is not a function"