<template>
<editor-content :editor="editor" />
</template>
<script setup>
import { useEditor, EditorContent } from '@tiptap/vue-3'
import StarterKit from '@tiptap/starter-kit'
const editor = useEditor({
content: "<p>I'm running Tiptap with Vue.js. 🎉</p>",
extensions: [StarterKit],
})
</script>
將這個組件帶入你想呈現的畫面,就會看到一個簡單的文字編輯內容
恩...但怎麼沒有格式設定?
npm install @tiptap/extension-text-style
import { EditorContent, useEditor } from '@tiptap/vue-3'
import StarterKit from '@tiptap/starter-kit'
import { Color, TextStyle, type TextStyleOptions } from '@tiptap/extension-text-style'
import { ListItem } from '@tiptap/extension-list'
const editor = useEditor({
extensions: [
Color.configure({ types: [TextStyle.name, ListItem.name] }),
TextStyle.configure({ types: [ListItem.name] } as Partial<TextStyleOptions>),
StarterKit,
],
content: `
<p>I'm running Tiptap with Vue.js. 🎉</p>
`,
})
就可以看到出現那些格式編輯的按鈕了
在官網可以看到
長得很像notion的編輯模板,但是要花錢
簡易編輯的模板,要額外安裝npx @tiptap/cli@latest add simple-editor
接著會開始載入tiptap ui元件
並且提醒要加入css設定
Add to src/index.css:
@import './styles/_variables.scss';
@import './styles/_keyframe-animations.scss';
Without these imports, the editor will not display correctly.
然後在想要顯示的元件裡引入
import { SimpleEditor } from '@/components/tiptap-templates/simple/simple-editor'
發現UI包都是React的tsx,結論如果是用vue的話就自己乖乖刻按鈕吧QQ
休息一下,晚點再繼續補充
有更新另一種模板帶入的方式