Skip to content

Instantly share code, notes, and snippets.

@jhillacre
Last active June 14, 2022 20:33
Show Gist options
  • Save jhillacre/7b9a9187d292b5823273c712ee46ff8a to your computer and use it in GitHub Desktop.
Save jhillacre/7b9a9187d292b5823273c712ee46ff8a to your computer and use it in GitHub Desktop.
TipTap Vue 3 starter component using script setup
<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