1、npm install vue-quill-editor
npm install quill
2、index.js引入
import VueQuillEditor from 'vue-quill-editor'
Vue.use(VueQuillEditor)
3、components文件夾新建xx.vue
寫法<template>
<!-- Or manually control the data synchronization(或手動控制數據流) -->
<div class="editor">
<quill-editor v-model="content"
ref="myQuillEditor"
:options="editorOption"
@blur="onEditorBlur($event)"
@focus="onEditorFocus($event)"
@ready="onEditorReady($event)">
</quill-editor>
<button @click="getContent()">獲取內容</button>
</div>
</template>
<script>
import Quill from 'quill'
import { ImageImport } from '../../static/quill/ImageImport.js'
import { ImageResize } from '../../static/quill/ImageResize.js'
Quill.register('modules/imageImport', ImageImport)
Quill.register('modules/imageResize', ImageResize)
// You can also register quill modules in the component
export default {
data () {
return {
content: '<h2>I am Example</h2>',
editorOption: {
modules: {
history: {
delay: 1000,
maxStack: 50,
userOnly: false
},
imageImport: true,
imageResize: {
displaySize: true
}
}
}
}
},
// if you need to manually control the data synchronization, parent component needs to explicitly emit an event instead of relying on implicit binding
// 若是須要手動控制數據同步,父組件須要顯式地處理changed事件
methods: {
onEditorBlur (editor) {
console.log('editor blur!', editor)
},
onEditorFocus (editor) {
console.log('editor focus!', editor)
},
onEditorReady (editor) {
console.log('editor ready!', editor)
},
onEditorChange ({ editor, html, text }) {
console.log('editor change!', editor, html, text)
this.content = html
},
getContent () {
alert(this.content)
}
},
mounted () {
// you can use current editor object to do something(quill methods)
console.log('this is current quill instance object', this.editor)
}
}
</script>
其中imageImport和imageResize 須要從github(vue-quill-editor)中的modules 中下載下來
效果
html