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

69 lines
1.5 KiB
Vue
Raw Normal View History

2018-09-01 02:42:13 +08:00
<template>
2018-11-09 05:03:10 +08:00
<div class="editor">
<editor-menu-bar :editor="editor" v-slot="{ commands }">
<div class="menubar">
2018-11-09 05:03:10 +08:00
<button
class="menubar__button"
@click="showImagePrompt(commands.image)"
>
<icon name="image" />
</button>
</div>
2018-11-09 05:44:07 +08:00
</editor-menu-bar>
2018-11-09 05:03:10 +08:00
<editor-content class="editor__content" :editor="editor" />
</div>
2018-09-01 02:42:13 +08:00
</template>
<script>
2018-09-30 04:49:38 +08:00
import Icon from 'Components/Icon'
2018-11-09 05:44:07 +08:00
import { Editor, EditorContent, EditorMenuBar } from 'tiptap'
2018-09-01 02:42:13 +08:00
import {
2018-11-09 05:03:10 +08:00
HardBreak,
Heading,
Image,
Bold,
Code,
Italic,
2018-09-01 02:42:13 +08:00
} from 'tiptap-extensions'
export default {
2018-11-09 05:03:10 +08:00
components: {
Icon,
EditorContent,
2018-11-09 05:44:07 +08:00
EditorMenuBar,
2018-11-09 05:03:10 +08:00
},
data() {
return {
editor: new Editor({
extensions: [
new HardBreak(),
new Heading({ levels: [1, 2, 3] }),
new Image(),
new Bold(),
new Code(),
new Italic(),
],
content: `
<h2>
Images
</h2>
<p>
This is basic example of implementing images. Try to drop new images here. Reordering also works.
</p>
2019-02-06 18:34:21 +08:00
<img src="https://66.media.tumblr.com/dcd3d24b79d78a3ee0f9192246e727f1/tumblr_o00xgqMhPM1qak053o1_400.gif" />
2018-11-09 05:03:10 +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
}
2018-11-09 05:03:10 +08:00
</script>