vue富文本編輯器組件vue-quill-edit使用教程
更新時間:2018年09月21日 11:29:31 作者:LIULIULIU666
這篇文章主要為大家詳細介紹了vue富文本編輯器組件vue-quill-edit的使用教程,具有一定的參考價值,感興趣的小伙伴們可以參考一下
之前使用的富文本編輯器是uEditor,kindEditor,感覺不太方便。
近期項目vue單頁面,就使用vue-quill-edit這個編輯器組件吧!
一、安裝 cnpm install vue-quill-editor
二、引入
在main.js引入并注冊:
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)
三、封裝組件
<template>
<div class="quill_box">
<quill-editor
v-model="content"
ref="myQuillEditor"
:options="editorOption"
@blur="onEditorBlur($event)" @focus="onEditorFocus($event)"
@change="onEditorChange($event)">
</quill-editor>
</div>
</template>
<script>
import Bus from "../../assets/utils/eventBus";
export default {
data() {
return {
content:'',
editorOption: {
placeholder: "請編輯內容",
modules: {
toolbar: [
["bold", "italic", "underline", "strike"],
["blockquote", "code-block"],
[{ list: "ordered" }, { list: "bullet" }],
[{ script: "sub" }, { script: "super" }],
[{ indent: "-1" }, { indent: "+1" }],
[{ size: ["small", false, "large", "huge"] }],
[{ font: [] }],
[{ color: [] }, { background: [] }],
[{ align: [] }],
[ "image"]
]
}
}
};
},
props:[
'contentDefault'
],
watch:{
contentDefault:function(){
this.content = this.contentDefault;
}
},
mounted:function(){
this.content = this.contentDefault;
},
methods: {
onEditorBlur() {
//失去焦點事件
// console.log('失去焦點');
},
onEditorFocus() {
//獲得焦點事件
// console.log('獲得焦點事件');
},
onEditorChange() {
//內容改變事件
// console.log('內容改變事件');
Bus.$emit('getEditorCode',this.content)
}
}
};
</script>
<style lang="less">
.quill_box{
.ql-toolbar.ql-snow{border-color:#dcdfe6;}
.ql-container{height:200px !important;border-color:#dcdfe6;}
.ql-snow .ql-picker-label::before {
position: relative;
top: -10px;
}
.ql-snow .ql-color-picker .ql-picker-label svg, .ql-snow .ql-icon-picker .ql-picker-label svg{position: relative;top:-6px;}
}
</style>
四、引入使用
<my-editor :contentDefault="contentDefault"></my-editor>
components:{
myEditor:myEditorComponent
},
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
vue使用Luckysheet插件實現(xiàn)excel導入導出
本文主要介紹了vue使用Luckysheet插件實現(xiàn)excel導入導出,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2024-03-03
vue+openlayer5獲取當前鼠標滑過的坐標實現(xiàn)方法
在vue項目中怎么獲取當前鼠標劃過的坐標呢?下面通過本文給大家分享實現(xiàn)步驟,感興趣的朋友跟隨小編一起看看吧2021-11-11
實例詳解Vue項目使用eslint + prettier規(guī)范代碼風格
這篇文章主要介紹了Vue項目使用eslint + prettier規(guī)范代碼風格,本文通過實例代碼給大家介紹的非常詳細,需要的朋友可以參考下2018-08-08
element 結合vue 在表單驗證時有值卻提示錯誤的解決辦法
這篇文章主要介紹了element 結合vue 在表單驗證下,有值卻提示錯誤的解決辦法,需要的朋友可以參考下2018-01-01
elementUI el-form 數(shù)據(jù)無法賦值且不報錯解決方法
本文主要介紹了elementUI el-form 數(shù)據(jù)無法賦值且不報錯解決方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-12-12

