Last active
June 14, 2022 20:33
-
-
Save jhillacre/7b9a9187d292b5823273c712ee46ff8a to your computer and use it in GitHub Desktop.
TipTap Vue 3 starter component using script setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div> | |
<editor-content :editor="editor" /> | |
</div> | |
</template> | |
<script setup> | |
import { EditorContent, useEditor } from "@tiptap/vue-3"; | |
import StarterKit from "@tiptap/starter-kit"; | |
import { toRef, unref, watch } from "vue"; | |
const props = defineProps({ | |
modelValue: { | |
type: String, | |
default: "", | |
}, | |
}); | |
const emit = defineEmits(["update:modelValue"]); | |
watch(toRef(props, "modelValue"), (value) => { | |
const unrefEditor = unref(editor); | |
if (editor.getHTML() === value) { | |
return; | |
} | |
editor.commandManager.setContent(value, false); | |
}); | |
const editor = useEditor({ | |
content: props.modelValue, | |
extensions: [StarterKit], | |
onUpdate: () => { | |
const unrefEditor = unref(editor); | |
emit("update:modelValue", unrefEditor.getHTML()); | |
}, | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment