<template>
<div>
<!--
<el-upload
id="upimg"
v-show="false"
class="upload-demo"
:action="imgUploadUrl"
:on-success="handleSuccess"
multiple
>
<el-button size="small" type="primary">点击上传</el-button>
</el-upload>
<!--
<quill-editor v-model="content" :options="editorOption" ref="QuillEditor">
</quill-editor>
</div>
</template>
<script>
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import { quillEditor } from 'vue-quill-editor'
const toolbarOptions = [
['bold', 'italic', 'underline', 'strike'],
['blockquote', 'code-block'],
[{ header: 1 }, { header: 2 }],
[{ list: 'ordered' }, { list: 'bullet' }],
[{ script: 'sub' }, { script: 'super' }],
[{ indent: '-1' }, { indent: '+1' }],
[{ direction: 'rtl' }],
[{ size: ['small', false, 'large', 'huge'] }],
[{ header: [1, 2, 3, 4, 5, 6, false] }],
[{ color: [] }, { background: [] }],
[{ font: [] }],
[{ align: [] }],
['link', 'image', 'video'],
['clean']
]
export default {
components: {
quillEditor
},
data() {
return {
imgUploadUrl: 'http://xxxxxxxx/fileUpload',
content: '',
editorOption: {
modules: {
toolbar: {
container: toolbarOptions,
handlers: {
image: function (value) {
if (value) {
document.querySelector('#upimg button').click()
} else {
this.quill.format('image', false)
}
}
}
}
}
}
}
},
methods: {
handleSuccess(res) {
const quill = this.$refs.QuillEditor.quill
if (res) {
const length = quill.getSelection().index
quill.insertEmbed(length, 'image', res.data)
quill.setSelection(length + 1)
} else {
this.$message.error('图片插入失败')
}
}
}
}
</script>
<style></style>