|  |  |  | 
|---|
|  |  |  | <template> | 
|---|
|  |  |  | <div :style="styleEditor"> | 
|---|
|  |  |  | <Toolbar style="border-bottom: 1px solid #ccc" :editor="editor" :defaultConfig="toolbarConfig" :mode="mode" /> | 
|---|
|  |  |  | <Editor style="height: 300px; overflow-y: hidden;" v-model="html" :defaultConfig="editorConfig" :mode="mode" | 
|---|
|  |  |  | <Editor style="min-height: 80px; overflow-y: hidden;" v-model="html" :defaultConfig="editorConfig" :mode="mode" | 
|---|
|  |  |  | @onCreated="onCreated" @onChange="onChange" /> | 
|---|
|  |  |  | </div> | 
|---|
|  |  |  | </template> | 
|---|
|  |  |  | 
|---|
|  |  |  | import Vue from 'vue' | 
|---|
|  |  |  | import { Editor, Toolbar } from '@wangeditor/editor-for-vue' | 
|---|
|  |  |  | import { Loading } from 'element-ui'; | 
|---|
|  |  |  | let loadingInstance = null | 
|---|
|  |  |  | export default Vue.extend({ | 
|---|
|  |  |  | props: { | 
|---|
|  |  |  | richData: { // 父组件传递的数据 | 
|---|
|  |  |  | 
|---|
|  |  |  | timeout: 10 * 1000, //10 秒 | 
|---|
|  |  |  | // 上传前 | 
|---|
|  |  |  | onBeforeUpload(files) { | 
|---|
|  |  |  | Loading.service({ | 
|---|
|  |  |  | loadingInstance = Loading.service({ | 
|---|
|  |  |  | lock: true, | 
|---|
|  |  |  | text: '上传中...', | 
|---|
|  |  |  | spinner: 'el-icon-loading', | 
|---|
|  |  |  | 
|---|
|  |  |  | console.log(res); | 
|---|
|  |  |  | // 因为自定义插入导致onSuccess与onFailed回调函数不起作用,自己手动处理 | 
|---|
|  |  |  | // 先关闭等待的Message | 
|---|
|  |  |  | Loading.service({ | 
|---|
|  |  |  | loadingInstance = Loading.service({ | 
|---|
|  |  |  | lock: true, | 
|---|
|  |  |  | text: '上传中...', | 
|---|
|  |  |  | spinner: 'el-icon-loading', | 
|---|
|  |  |  | 
|---|
|  |  |  | // 单个文件上传失败 | 
|---|
|  |  |  | onFailed(file, res) { | 
|---|
|  |  |  | console.log(`${file.originalFilename} 上传失败`, res); | 
|---|
|  |  |  | loadingInstance.close(); | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | // 上传进度的回调函数 | 
|---|
|  |  |  | onProgress(progress) { | 
|---|
|  |  |  | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | // 上传错误,或者触发 timeout 超时 | 
|---|
|  |  |  | onError(file, err, res) { | 
|---|
|  |  |  | loadingInstance.close(); | 
|---|
|  |  |  | console.log(`${file.originalFilename} 上传出错`, err, res); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }, | 
|---|