1.配置webpack plugincss
解決如下報錯vue
Uncaught TypeError: Cannot read property 'imports' of undefined (image-resize.min.js?c9ce:1)
// 在vue.config.js中configureWebpack中配置 // 要引入webpack var webpack = require('webpack'); configureWebpack: { plugins: [ new webpack.ProvidePlugin({ 'window.Quill': 'quill/dist/quill.js', 'Quill': 'quill/dist/quill.js' }), ] }
2.在main.js中添加如下內容webpack
import VueQuillEditor from 'vue-quill-editor' // require styles import 'quill/dist/quill.core.css' import 'quill/dist/quill.snow.css' import 'quill/dist/quill.bubble.css' Vue.use(VueQuillEditor)
3.vue組件使用模板web
1 <template> 2 <quill-editor ref="myTextEditor" 3 v-model="content" 4 :options="editorOption" 5 @blur="onEditorBlur($event)"> 6 </quill-editor> 7 </template> 8 9 <script> 10 import hljs from 'highlight.js' 11 import VueQuillEditor, { Quill } from 'vue-quill-editor' 12 import { ImageDrop } from 'quill-image-drop-module' 13 import ImageResize from 'quill-image-resize-module' 14 Quill.register('modules/imageDrop', ImageDrop) 15 Quill.register('modules/imageResize', ImageResize) 16 17 export default { 18 name: "myEditor", 19 data(){ 20 return{ 21 editorOption: { 22 modules: { 23 toolbar: [ 24 ['bold', 'italic', 'underline', 'strike'], 25 ['blockquote', 'code-block'], 26 [{ 'header': 1 }, { 'header': 2 }], 27 [{ 'list': 'ordered' }, { 'list': 'bullet' }], 28 [{ 'script': 'sub' }, { 'script': 'super' }], 29 [{ 'indent': '-1' }, { 'indent': '+1' }], 30 [{ 'direction': 'rtl' }], 31 [{ 'size': ['small', false, 'large', 'huge'] }], 32 [{ 'header': [1, 2, 3, 4, 5, 6, false] }], 33 [{ 'font': [] }], 34 [{ 'color': [] }, { 'background': [] }], 35 [{ 'align': [] }], 36 ['clean'], 37 ['link', 'image', 'video'] 38 ], 39 history: { 40 delay: 1000, 41 maxStack: 50, 42 userOnly: false 43 }, 44 imageDrop: true, 45 imageResize: { 46 displayStyles: { 47 backgroundColor: 'black', 48 border: 'none', 49 color: 'white' 50 }, 51 modules: [ 'Resize', 'DisplaySize', 'Toolbar' ] 52 } 53 } 54 }, 55 content:'' 56 } 57 }, 58 methods:{ 59 onEditorBlur:function () { 60 console.log(this.content) 61 } 62 } 63 } 64 </script> 65 66 <style scoped> 67 68 </style>