tiptap/docs/src/demos/Extensions/TextAlign/index.vue

58 lines
1.2 KiB
Vue
Raw Normal View History

2020-10-23 21:23:40 +08:00
<template>
<div v-if="editor">
2020-10-23 23:50:28 +08:00
<button @click="editor.chain().focus().textAlign('left').run()">
2020-10-23 21:23:40 +08:00
left
</button>
2020-10-23 23:50:28 +08:00
<button @click="editor.chain().focus().textAlign('center').run()">
2020-10-23 21:23:40 +08:00
center
</button>
2020-10-23 23:50:28 +08:00
<button @click="editor.chain().focus().textAlign('right').run()">
2020-10-23 21:23:40 +08:00
right
</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'
2020-10-23 23:19:12 +08:00
import Heading from '@tiptap/extension-heading'
2020-10-23 21:23:40 +08:00
import Text from '@tiptap/extension-text'
import TextAlign from '@tiptap/extension-text-align'
export default {
components: {
EditorContent,
},
data() {
return {
editor: null,
}
},
mounted() {
this.editor = new Editor({
extensions: [
Document(),
Paragraph(),
Text(),
2020-10-23 23:19:12 +08:00
Heading(),
2020-10-23 21:23:40 +08:00
TextAlign(),
],
content: `
2020-10-24 05:41:54 +08:00
<h2>Heading</h2>
2020-10-23 23:19:12 +08:00
<p style="text-align: center">first paragraph</p>
<p style="text-align: right">second paragraph</p>
2020-10-23 21:23:40 +08:00
`,
})
},
beforeDestroy() {
this.editor.destroy()
},
}
</script>