tiptap/examples/Components/Routes/Images/index.vue

68 lines
1.2 KiB
Vue
Raw Normal View History

2018-09-01 02:42:13 +08:00
<template>
2018-10-23 03:46:45 +08:00
<div class="editor">
2018-11-05 05:43:26 +08:00
<menu-bar :editor="editor">
<div class="menubar" slot-scope="{ commands }">
2018-10-23 03:46:45 +08:00
<button
class="menubar__button"
2018-10-29 05:57:05 +08:00
@click="showImagePrompt(commands.image)"
2018-10-23 03:46:45 +08:00
>
<icon name="image" />
</button>
2018-11-05 05:43:26 +08:00
</div>
2018-10-23 03:46:45 +08:00
</menu-bar>
<editor-content class="editor__content" :editor="editor" />
2018-09-01 02:42:13 +08:00
</div>
</template>
<script>
2018-09-30 04:49:38 +08:00
import Icon from 'Components/Icon'
2018-10-23 03:46:45 +08:00
import { Editor, EditorContent, MenuBar } from 'tiptap'
2018-09-01 02:42:13 +08:00
import {
2018-10-24 13:46:47 +08:00
HardBreak,
Heading,
Image,
Bold,
Code,
Italic,
2018-09-01 02:42:13 +08:00
} from 'tiptap-extensions'
export default {
components: {
2018-09-30 04:49:38 +08:00
Icon,
2018-10-23 03:46:45 +08:00
EditorContent,
MenuBar,
2018-09-01 02:42:13 +08:00
},
data() {
return {
2018-10-23 03:46:45 +08:00
editor: new Editor({
extensions: [
2018-10-24 13:46:47 +08:00
new HardBreak(),
new Heading({ levels: [1, 2, 3] }),
2018-10-24 13:46:47 +08:00
new Image(),
new Bold(),
new Code(),
new Italic(),
2018-10-23 03:46:45 +08:00
],
content: `
<h2>
Images
</h2>
<p>
This is basic example of implementing images. Try to drop new images here. Reordering also works.
</p>
<img src="https://ljdchost.com/8I2DeFn.gif" />
`,
}),
2018-09-01 02:42:13 +08:00
}
},
2018-09-30 04:49:38 +08:00
methods: {
showImagePrompt(command) {
const src = prompt('Enter the url of your image here')
if (src !== null) {
command({ src })
}
},
},
2018-09-01 02:42:13 +08:00
}
</script>