editor修改样式vue_vue-quill-editor的使⽤及个性化定制操作最近在⽤vue + element ui写⼀个⼩应⽤要⽤到富⽂本编辑器,以前做项⽬都⼀直都⽤ueditor,但是看了⼀下它与vue的兼容性并不好,⼜对⽐了⼏个后,选择了vue-quill-editor。
vue-quill-editor基于Quill、适⽤于 Vue 的富⽂本编辑器,⽀持服务端渲染和单页应⽤,正是我想要的☻。这⾥只介绍基本的安装和部分简单的定制。我翻了很多别⼈写的东西对我的项⽬都⽆效,最后⾃⼰折腾出来在这记录备忘。
⼀、安装
1.安装模块
npm install vue-quill-editor –save
2.vue组件
v-model="content"
ref="myQuillEditor"
:options="editorOption"
@blur="onEditorBlur($event)" @focus="onEditorFocus($event)"
@change="onEditorChange($event)">
import 'quill/ss'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import { quillEditor } from 'vue-quill-editor';
export default {
name: "addJournal",
components: {
quillEditor
},
data() {
return {
content: ``,
editorOption: {},
};
},
methods: {
onEditorReady(editor) {}, // 准备编辑器
onEditorBlur(){}, // 失去焦点事件
onEditorFocus(){}, // 获得焦点事件
onEditorChange(){}, // 内容改变事件
import * as Quill from 'quill';
let fontSizeStyle = Quill.import('attributors/style/size');
fontSizeStyle.whitelist = ['10px', '12px', '14px', '16px', '20px', '24px', '36px', false];//false表⽰默认值
step2: 修改quill-editor的option属性值
editorOption: {
modules: {
toolbar: [["bold", "italic", "underline", "strike"], ["blockquote", "code-block"], [{header: 1}, {header: 2}], [{list: "ordered"}, {list: "bullet"}], [{script: "sub"}, {script: "super"}], [{indent: "-1"}, {indent: "+1"}], [{direction: "rtl"}],
[{size: fontSizeStyle.whitelist}], [{header: [1, 2, 3, 4, 5, 6, !1]}], [{color: []}, {background: []}], [{font: []}], [{align: []}], ["clean"], ["link", "image", "video"]],
},
}
这个modules⾥⾯的值是参照vue-quill-editor模块⾥的vue-quill-editor.js⾥的modules值设置的,只需要将你要修改的⼯具栏按钮的值替换成step1⾥设置的whitelist值即可。
step3: 增加定制选项的css样式
.ql-snow .ql-picker.ql-size .ql-picker-label[data-value='10px']::before, .ql-snow .ql-picker.ql-size .ql-picker-item[data-
value='10px']::before {
content: '10px';
}
.ql-snow .ql-picker.ql-size .ql-picker-label[data-value='12px']::before, .ql-snow .ql-picker.ql-size .ql-picker-item[data-
value='12px']::before {
content: '12px';
}
.ql-snow .ql-picker.ql-size .ql-picker-label[data-value='14px']::before, .ql-snow .ql-picker.ql-size .ql-picker-item[data-
value='14px']::before {
content: '14px';
}
.ql-snow .ql-picker.ql-size .ql-picker-label[data-value='16px']::before, .ql-snow .ql-picker.ql-size .ql-picker-item[data-
value='16px']::before {
content: '16px';
}
.ql-snow .ql-picker.ql-size .ql-picker-label[data-value='20px']::before, .ql-snow .ql-picker.ql-size .ql-picker-item[data-优秀的富文本编辑器
value='20px']::before {
content: '20px';
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。