npm install vue-quill-editor //富文本編輯器vue
npm install quill //依賴項web
(2)在main.js中引入文件npm
import Vue from 'vue'app
import VueQuillEditor from 'vue-quill-editor'less
import 'quill/dist/quill.core.css'編輯器
import 'quill/dist/quill.snow.css'ide
import 'quill/dist/quill.bubble.css'post
Vue.use(VueQuillEditor)字體
(3)建立屬於本身的富文本編輯器組件
<template>
<div class="edit_container">
<quill-editor
v-model="content"
ref="myQuillEditor"
:options="editorOption"
@blur="onEditorBlur($event)" @focus="onEditorFocus($event)"
@change="onEditorChange($event)">
</quill-editor>
</div>
</template>
<script>
export default {
name: 'App',
data(){
return {
content: "1111",
editorOption: {
modules:{
toolbar:[
['bold', 'italic', 'underline', 'strike'], //加粗,斜體,下劃線,刪除線
['blockquote', 'code-block'], //引用,代碼塊
[{ 'header': 1 }, { 'header': 2 }], // 標題,鍵值對的形式;一、2表示字體大小
[{ 'list': 'ordered'}, { 'list': 'bullet' }], //列表
[{ 'script': 'sub'}, { 'script': 'super' }], // 上下標
[{ 'indent': '-1'}, { 'indent': '+1' }], // 縮進
[{ 'direction': 'rtl' }], // 文本方向
[{ 'size': ['small', false, 'large', 'huge'] }], // 字體大小
[{ 'header': [1, 2, 3, 4, 5, 6, false] }], //幾級標題
[{ 'color': [] }, { 'background': [] }], // 字體顏色,字體背景顏色
[{ 'font': [] }], //字體
[{ 'align': [] }], //對齊方式
['clean'], //清除字體樣式
['image','video'] //上傳圖片、上傳視頻
]
},
theme:'snow',
placeholder: "請輸入內容..."
}
}
},
computed: {
editor() {
return this.$refs.myQuillEditor.quill;
},
},
methods: {
onEditorReady(editor) { // 準備編輯器
},
onEditorBlur(){}, // 失去焦點事件
onEditorFocus(){}, // 得到焦點事件
onEditorChange(){}, // 內容改變事件
saveHtml:function(event){
alert(this.content);
}
}
}
</script>
<style lang="less">
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
.edit_container {
margin: 10px 0;
}
.quill-editor {
height: 200px;
}
</style>
(4)在須要使用富文本編輯器的頁面中引用該組件
JS文件中:
//注意:經過VueQuillEditor能夠在當前文件獲取和操做富文本組件的內容
import VueQuillEditor from '@crm_components/VueQuillEditor';
components: {
"vue-quill-editor": VueQuillEditor, //富文本編輯器
}
Vue文件中:
<vue-quill-editor ></vue-quill-editor>