vue富文本编辑器

基于webpack和vue

一、npm 安装 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>

<quill-editor
v-model="content"
ref="myQuillEditor"
:options="editorOption"
@blur="onEditorBlur($event)" @focus="onEditorFocus($event)"
@change="onEditorChange($event)">
</quill-editor>
</template>
<script>
import { quillEditor } from 'vue-quill-editor'
export default{
data(){
return {
content:null,
editorOption:{}
}
},
methods:{
onEditorBlur(){//失去焦点事件
},
onEditorFocus(){//获得焦点事件
},
onEditorChange(){//内容改变事件
}
}
}
</script>
引入后会得到这样一个编辑器
在https://quilljs.com/docs/themes/这个官方文档里面看到了类似的方法

初始值的设置应该是一样的吧
所以我就照着toolbar部分去修改了options

<script>
import { quillEditor } from 'vue-quill-editor'
export default{
data(){
return {
content:null,
editorOption:{
modules:{
toolbar:[
['bold', 'italic', 'underline', 'strike'], // toggled buttons
['blockquote', 'code-block']
]
}
}
}
},
methods:{
onEditorBlur(){//失去焦点事件
},
onEditorFocus(){//获得焦点事件
},
onEditorChange(){//内容改变事件
}
}
}
</script>
那么toolbar工具栏对应功能的模块名是什么呢 我继续往下看文档 发现大致上有以下的功能

背景颜色 - background
加粗- bold
颜色 - color
字体 - font
内联代码 - code
斜体 - italic
链接 - link
大小 - size
删除线 - strike
上标/下标 - script
下划线 - underline
引用- blockquote
标题 - header
缩进 - indent
列表 - list
文本对齐 - align
文本方向 - direction
代码块 - code-block
公式 - formula
图片 - image
视频 - video
清除字体样式- clean

然而我试着直接引入发现有部分的图标并没有显示;
然后我发现他有些如list这种列表应该是有默认值,我在很后面的文档里发现了这个默认格式规范 这个官方文档也是个坑 内容不写到一块的 还好我聪明机智;

 

大致上分为这几类:

1.只需要填写功能名的
加粗 - bold;
斜体 - italic
下划线 - underline
删除线 - strike
引用- blockquote
代码块 - code-block
公式 - formula
图片 - image
视频 - video
清除字体样式- clean
这一类的引用 直接['name','name']这种格式就好了

2.需要有默认值的
标题 - header
[{ 'header': 1 }, { 'header': 2 }] 值字体大小

列表 - list
[{ 'list': 'ordered'}, { 'list': 'bullet' }], 值ordered,bullet

上标/下标 - script
[{ 'script': 'sub'}, { 'script': 'super' }], 值sub,super

缩进 - indent
[{ 'indent': '-1'}, { 'indent': '+1' }], 值-1,+1等

文本方向 - direction
[{ 'direction': 'rtl' }], 值rtl

3.有多个值 以下拉列表形式显示

大小 - size
[{ 'size': ['small', false, 'large', 'huge'] }],

标题 - header
[{ 'header': [1, 2, 3, 4, 5, 6, false] }],

4.有系统默认值的功能只需填写一个空数组 就会有出现默认的选项
颜色 - color
背景颜色 - background
字体 - font
文本对齐 - align
他们的格式都是
[{ 'color': [] }, { 'background': [] }],
[{ 'font': [] }],
[{ 'align': [] }]

toolbar自定义工具栏就是这样咯 剩下的就是根据填写功能到options的modules里就可以了

转载于:https://www.cnblogs.com/tis100204/p/10760609.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值