组件代码
<template>
<div>
<quill-editor v-model="content" ref="quill" :options="editorOption" class="editor">
</quill-editor>
<input type="file" @change="onEditorChange" id="upload" style="display:none;" />
</div>
</template>
<script>
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import service from '@/utils/service'
import { quillEditor, Quill } from 'vue-quill-editor'
import { container, ImageExtend, QuillWatch } from 'quill-image-extend-module'
// import { ImageDrop } from 'quill-image-drop-module'
import ImageResize from 'quill-image-resize-module'
Quill.register('modules/ImageExtend', ImageExtend)
// Quill.register('modules/imageDrop', ImageDrop)
Quill.register('modules/imageResize', ImageResize)
function uploadImage(file) {
return service({
method: 'post',
// url: `${process.env.VUE_APP_API}/file/post-commit`,
url: `${process.env.VUE_APP_API}/file/post`,
data: file,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
}
function getPageBaseUrl () {
let baseURL = ''
if (!window.location.origin) { // 兼容IE,IE11版本下location.origin为undefined
window.location.origin = window.location.protocol + '//' + window.location.hostname + (window.location.port ? ':' + window.location.port : '')
} else {
baseURL = window.location.origin
}
return baseURL
}
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' }],
[{ size: ['small', false, 'large', 'huge