tiptap/docs/src/demos/Nodes/Heading/index.vue

60 lines
1.5 KiB
Vue
Raw Normal View History

2020-09-10 23:10:20 +08:00
<template>
<div v-if="editor">
2020-09-22 15:08:08 +08:00
<button @click="editor.chain().focus().heading({ level: 1 }).run()" :class="{ 'is-active': editor.isActive('heading', { level: 1 }) }">
2020-09-10 23:10:20 +08:00
h1
</button>
2020-09-22 15:08:08 +08:00
<button @click="editor.chain().focus().heading({ level: 2 }).run()" :class="{ 'is-active': editor.isActive('heading', { level: 2 }) }">
2020-09-10 23:10:20 +08:00
h2
</button>
2020-09-22 15:08:08 +08:00
<button @click="editor.chain().focus().heading({ level: 3 }).run()" :class="{ 'is-active': editor.isActive('heading', { level: 3 }) }">
2020-09-10 23:10:20 +08:00
h3
</button>
<editor-content :editor="editor" />
</div>
</template>
<script>
import { Editor } from '@tiptap/core'
import { EditorContent } from '@tiptap/vue'
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import Heading from '@tiptap/extension-heading'
export default {
components: {
EditorContent,
},
data() {
return {
editor: null,
}
},
mounted() {
this.editor = new Editor({
extensions: [
2020-11-16 16:43:17 +08:00
Document,
Paragraph,
Text,
2020-11-16 18:07:06 +08:00
Heading.configure({
2020-09-10 23:10:20 +08:00
levels: [1, 2, 3],
}),
],
content: `
2020-09-23 18:03:03 +08:00
<h1>This is a 1st level heading</h1>
<h2>This is a 2nd level heading</h2>
<h3>This is a 3rd level heading</h3>
<h4>This 4th level heading will be converted to a paragraph, because levels are configured to be only 1, 2 or 3.</h4>
2020-09-10 23:10:20 +08:00
`,
})
},
beforeDestroy() {
this.editor.destroy()
2020-09-24 06:29:05 +08:00
},
2020-09-10 23:10:20 +08:00
}
2020-09-24 06:29:05 +08:00
</script>