下面是实现效果
首先咱们是用在vue项目中的,使用的是vue-quill-editor插件
若是想知道vue-quill-editor的基础用法和图片上传能够看看我以前写的一篇文章
基本用法:
https://github.com/surmon-china/vue-quill-editor
富文本框图片上传七牛:
http://www.javashuo.com/article/p-yldiedjp-eb.htmlvue
咱们这里主要讲述配置字体大小选择框
在使用组件界面作配置
一、导入Quillgit
import * as Quill from 'quill'
二、配置字体列表,主要是修改Quill、attributors/style/sizegithub
let fontSizeStyle = Quill.import('attributors/style/size') fontSizeStyle.whitelist = ['12px', '14px', '16px', '20px', '24px', '36px'] Quill.register(fontSizeStyle, true)
三、定义配置项segmentfault
const toolbarOptions = [ ['bold', 'italic', 'underline', 'strike'], [{'color': []}, { 'size': fontSizeStyle.whitelist }], [{ list: 'ordered' }, { list: 'bullet' }], [{ indent: '-1' }, { indent: '+1' }], ['link', 'image'] ]
四、使用编辑器
data () { return { editorOption: { placeholder: '请输入', theme: 'snow', modules: { toolbar: { container: toolbarOptions } } } } } <quill-editor v-model="content" ref="myQuillEditor" :options="editorOption" @change="onEditorChange($event)" > </quill-editor>
总体使用代码工具
<template> <div id='quillEditorQiniu'> <quill-editor v-model="content" ref="myQuillEditor" :options="editorOption" @change="onEditorChange($event)" > </quill-editor> </div> </template> <script> import { quillEditor } from 'vue-quill-editor' import * as Quill from 'quill' let fontSizeStyle = Quill.import('attributors/style/size') fontSizeStyle.whitelist = ['12px', '14px', '16px', '20px', '24px', '36px'] Quill.register(fontSizeStyle, true) const toolbarOptions = [ ['bold', 'italic', 'underline', 'strike'], [{'color': []}, { 'size': fontSizeStyle.whitelist }], [{ list: 'ordered' }, { list: 'bullet' }], [{ indent: '-1' }, { indent: '+1' }], ['link', 'image'] ] // 自定义编辑器的工做条 export default { components: { quillEditor }, mounted () { // 工具栏中的图片图标被单击的时候调用这个方法 let imgHandler = function (state) { if (state) { document.querySelector('.avatar-uploader input').click() } } // 当工具栏中的图片图标被单击的时候 this.$refs.myQuillEditor.quill.getModule('toolbar').addHandler('image', imgHandler) }, data () { return { editorOption: { placeholder: '请输入', theme: 'snow', modules: { toolbar: { container: toolbarOptions } } } } } } </script>