I wonder if I am doing it right, but currently I am wrapping the tiptap editor-content into a self-defined component like this:
export default {
props: { value: String },
data() { return { editor: null } },
watch: {
content: {
handler() {
if (this.editor) this.editor.destroy()
this.editor = new Editor({ content: this.value, ... })
},
immediate: true
},
},
beforeDestroy() {
this.editor.destroy()
}
What I want to do is to re-set the content of the editor when the value prop changes. But each time when it changes, I have to destroy and re-new the editor again. I wonder if there is some better way to do this without recreating the editor object.
Yeah, you can use editor.setContent() and editor.clearContent() for that!
Most helpful comment
Yeah, you can use
editor.setContent()andeditor.clearContent()for that!