本篇文章為大家展示了如何在vue中使用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); // 富文本改變時的內容
}
}
}Vue是一款友好的、多用途且高性能的JavaScript框架,使用vue可以創建可維護性和可測試性更強的代碼庫,Vue允許可以將一個網頁分割成可復用的組件,每個組件都包含屬于自己的HTML、CSS、JavaScript,以用來渲染網頁中相應的地方,所以越來越多的前端開發者使用vue。
上述內容就是如何在vue中使用vue-quill-editor富文本編輯器,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。