vue-quill-editor富文字編輯器簡單使用方法
阿新 • • 發佈:2020-12-08
文章剛開始先來介紹一下vue-quill-editor富文字編輯器的簡單使用,具體操作步驟如下:
安裝:
npm install vue-quill-editor --save
main.js:
import VueQuillEditor from 'vue-quill-editor' import 'quill/dist/quill.core.css' import 'quill/dist/quill.snow.css' import 'quill/dist/quill.bubble.css'
在需要使用的地方
<template> <quill-editor v-model="content" ref="myQuillEditor" :options="editorOption" @blur="onEditorBlur($event)" @focus="onEditorFocus($event)" @change="onEditorChange($event)"> </quill-editor> </template> <script> import { quillEditor } from 'vue-quill-editor' export default{ data(){ return { content:null, editorOption:{} //配置 } }, methods:{ onEditorBlur(){//失去焦點事件 }, onEditorFocus(){//獲得焦點事件 }, onEditorChange(){//內容改變事件 } } } </script>
看到了一個網友分享的如何禁用vue-quill-editor 富文字編輯器,分享給大家,也謝謝原作者的分享。
vue:
<el-form-item label="描述:" :label-width="formLabelWidth"> <quill-editor v-model="form.content" ref="content" :options="editorOption" @blur="onEditorBlur($event)" @focus="onEditorFocus($event)" @change="onContentChange($event)" @ready="onEditorReady($event)"> </quill-editor> </el-form-item>
js:
export default {
data() {
form: {
content:'', // 儲存富文字框內容
},
editorOption: { // 定義富文字編輯器顯示
modules:{
toolbar:[
['bold','italic','underline','strike'], // 加粗、傾斜、下劃線、刪除線
[{'header':1},{'header':2}], // 標題一、標題二
[{'list':'ordered'},{'list':'bullet'}], // 列表
[{'color':[]},{'background':[]}], // 字型顏色、背景顏色
]
}
}
},
methods: {
onEditorReady(){ // 富文字準備時的事件
},
onEditorFocus(val,editor){ // 富文字獲得焦點時的事件
console.log(val); // 富文字獲得焦點時的內容
editor.enable(false); // 在獲取焦點的時候禁用
},
onEditorBlur(val){ // 富文字失去焦點時的事件
console.log(val); // 富文字失去焦點時的內容
},
onContentChange(val){ // 富文字內容改變時的事件
console.log(val); // 富文字改變時的內容
}
}
}
toolbar具體配置參考網址:https://blog.csdn.net/div_ma/article/details/79536634
https://blog.csdn.net/qq_42817227/article/details/88524528