文檔地址:https://quilljs.com/docs/quickstart/
css
github地址:https://github.com/surmon-china/vue-quill-editor
使用方法:html
#### NPM
npm install vue-quill-editor --save
#### mian.js
import Vue from 'vue'
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, /* { default global options } */)
### 使用 demo
<template>
<!-- bidirectional data binding(雙向數據綁定) -->
<quill-editor v-model="content"
ref="myQuillEditor"
:options="editorOption"
@blur="onEditorBlur($event)"
@focus="onEditorFocus($event)"
@ready="onEditorReady($event)">
</quill-editor>
<!-- Or manually control the data synchronization(或手動控制數據流) -->
<quill-editor :content="content"
:options="editorOption"
@change="onEditorChange($event)">
</quill-editor>
</template>
<script>
// you can also register quill modules in the component
import Quill from 'quill'
import { someModule } from '../yourModulePath/someQuillModule.js'
Quill.register('modules/someModule', someModule)
export default {
data () {
return {
content: '<h2>I am Example</h2>',
editorOption: {
// some quill options
}
}
},
// manually control the data synchronization
// 若是須要手動控制數據同步,父組件須要顯式地處理changed事件
methods: {
onEditorBlur(quill) {
console.log('editor blur!', quill)
},
onEditorFocus(quill) {
console.log('editor focus!', quill)
},
onEditorReady(quill) {
console.log('editor ready!', quill)
},
onEditorChange({ quill, html, text }) {
console.log('editor change!', quill, html, text)
this.content = html
}
},
computed: {
editor() {
return this.$refs.myQuillEditor.quill
}
},
mounted() {
console.log('this is current quill instance object', this.editor)
}
}
</script>
複製代碼
問題一:輸入文字出現首字母的問題vue
刪除node_modules
刪除 package-lock.json
最後npm install
這個問題很奇怪我看不少博客都是經過這個方式解決的,確實能夠解決這個問題
複製代碼
問題二:字體樣式丟失node
解決方案: js:git
import Quill from 'quill'
github
var Size = Quill.import('attributors/style/size');
npm
Size.whitelist = ['10px', '12px', '14px', '16px', '18px', '20px', '32px'];
json
Quill.register(Size, true);
bash
<style>
.ql-toolbar{
white-space: normal;
}
.ql-picker-item[data-value='10px']::before, .ql-picker-label[data-value='10px']::before {
content: '10px' !important;
}
.ql-picker-item[data-value='12px']::before, .ql-picker-label[data-value='12px']::before {
content: '12px' !important;
}
.ql-picker-item[data-value='14px']::before, .ql-picker-label[data-value='14px']::before {
content: '14px' !important;
}
.ql-picker-item[data-value='16px']::before, .ql-picker-label[data-value='16px']::before {
content: '16px' !important;
}
.ql-picker-item[data-value='18px']::before, .ql-picker-label[data-value='18px']::before {
content: '18px' !important;
}
.ql-picker-item[data-value='20px']::before, .ql-picker-label[data-value='20px']::before {
content: '20px' !important;
}
.ql-picker-item[data-value='24px']::before, .ql-picker-label[data-value='24px']::before {
content: '24px' !important;
}
.ql-picker-item[data-value='30px']::before, .ql-picker-label[data-value='30px']::before {
content: '30px' !important;
}
.ql-picker-item[data-value='32px']::before, .ql-picker-label[data-value='32px']::before {
content: '32px' !important;
}
.ql-picker-item[data-value='36px']::before, .ql-picker-label[data-value='36px']::before {
content: '36px' !important;
}
<style>
![](https://user-gold-cdn.xitu.io/2018/11/7/166ec4433f2db714?w=1018&h=268&f=png&s=64861)
複製代碼
問題三:縮進indent轉爲style字體
IndentStyle.js
var Parchment = Quill.import("parchment")
const levels = [1, 2, 3, 4, 5];
const multiplier = 2;
export default class IndentAttributor extends Parchment.Attributor.Style {
add(node, value) {
return super.add(node, `${value * multiplier}em`);
}
value(node) {
return parseFloat(super.value(node)) / multiplier || undefined; // Don't return NaN } } const IndentStyle = new IndentAttributor('indent', 'margin-left', { scope: Parchment.Scope.BLOCK, whitelist: levels.map(value => `${value * multiplier}em`) }); Quill.register(IndentStyle); 複製代碼
import Quill from 'quill'
import IndentStyle from './Indent.js';
...下面就正常使用就行了
![](https://user-gold-cdn.xitu.io/2018/11/7/166ec44a8a529b79?w=1208&h=246&f=png&s=97191)
複製代碼
問題四:禁止富文本編輯
場景:好比有些時候文章須要下架,那麼下架的時候是不容許編輯的
this.$refs.myQuillEditor.quill.enable(false)
// false禁止編輯 true語序編輯
複製代碼