当前位置:网站首页>wangEditor介绍(入门级)
wangEditor介绍(入门级)
2022-07-17 00:17:00 【发臭的 靈魂】
一、什么是富文本编辑器?
相信很多小伙伴都用过富文本编辑器。富文本编辑器(Rich Text Editor,RTE)是一种可内嵌于浏览器,所见即所得的文本编辑器。可以实现很多功能,如改变字体颜色,插入图片视频等,应用十分广泛。市场上主流的编辑器也有不少,如TinyMCE,CKEditor,wangEditor等。每一款都有独特的地方,只有使用过才体会深刻。今天,我们主要介绍wangEditor。因为最近项目中集成了wangEditor,所以作为新手,将使用体会记录如下。
二、wangEditor介绍
wangEditor是一款轻量级 web 富文本编辑器,配置方便,使用简单,开源免费。支持 IE10+ 浏览器。
三、下载
npm i wangeditor --save
或
yarn add wangeditor --save
四、使用
4-1: 引用到项目
1.如果是通过npm/yarn 下载wangeditor ;
import E from 'wangeditor'
const editor = new E('#div1')
// 或者 const editor = new E( document.getElementById('div1') )
editor.create()
2.js外链引用的方式也分两种(在线链接引用和本地资源引用)
<script src="https://unpkg.com/wangeditor/release/wangEditor.min.js"></script>
<!--此处的src也可以是本地资源链接 -->
<script type="text/javascript">
const E = window.wangEditor
const editor = new E("#div1")
// 或者 const editor = new E(document.getElementById('div1'))
editor.create()
</script>
注意:一个页面可创建多个编辑器
//创建多个编辑器
<script>
var E = window.wangEditor
//第一个编辑器
var editor1 = new E('#div1')
editor1.create()
//第二个编辑器
var editor2 = new E('#div2')
editor2.create()
</script>
4-2:分离菜单栏和编辑栏区域
<div id="div3">菜单区</div>
<div>--------------------------------</div>
<div id="div4">编辑区</div>
<script>
//先实例化wangEditor,再分别用两个DOM渲染菜单区和编辑区var E = window.wangEditorvar editor2 = new E('#div3','#div4')
editor2.create()
</script>
4-3:配置菜单区和编辑区内容
<script>
var E = window.wangEditor
var editor1 = new E('#div1')
//配置菜单栏
// 如果菜单栏宽度不够,建议精简菜单项。
editor1.customConfig.menus = [
'head', // 标题
'bold', // 粗体
'fontSize', // 字号
'fontName', // 字体
'italic', // 斜体
'underline', // 下划线
'strikeThrough', // 删除线
'foreColor', // 文字颜色
'backColor', // 背景颜色
'link', // 插入链接
'list', // 列表
'justify', // 对齐方式
'quote', // 引用
'emoticon', // 表情
'image', // 插入图片
'table', // 表格
'video', // 插入视频
'code', // 插入代码
'undo', // 撤销
'redo' // 重复
]
// 配置颜色
editor1.customConfig.colors = [
'#000000',
...
// 可自行添加
]
// 配置字体
editor1.customConfig.fontNames = [
'宋体',
'微软雅黑',
'Arial', ...
// 可自行添加
]
editor1.create()
</script>
最后,附上 wangEditor官方文档,更多内容等你探索!
边栏推荐
- Shortest circuit / secondary short circuit /k short circuit
- Leetcode 70:Climbing Stairs
- String Full Permutation Problem
- Traversal of binary tree
- rsync远程同步(增量备份)
- 使用Virtual IP+Keepalived配置高可用
- Unicast、Multicast、Broadcast
- Zabbix6.0通过iDRAC,IMM2监控DELL,IBM服务器硬件
- 服务账户service account在kubernetes1.24中的变化
- Interface (collection/map) - implementation and comparison of interfaces
猜你喜欢
随机推荐
Gzip的动态压缩和静态压缩详解
The JMeter BeanShell implementation writes the parameterized data generated by the request to the file
使用Virtual IP+Keepalived配置高可用
RHCE8学习指南第一章 安装RHEL8.4
Shell脚本整数值比较、逻辑测试、if语句、提取性能监控指标
[solved] after referring to the local MySQL and forgetting the password, [server] --initialize specified but the data directory has files in it Aborti
LAMP平台部署及应用
ctfhub--ssrf
正则、扩展表达式,sed文本处理器与awk工具、用脚本改IP地址
HCIA_NAT实验
Keep two decimal places and take values upward
C语言回调函数 & sprinf 实际应用一例
Bladex - a well-designed microservice architecture
Circular statements and functions of shell scripts
Shell script for, while loop statements, price guessing games
数组、冒泡的认识
Services for NFS
RHCE8学习指南第2章 基本命令的使用
服务账户service account在kubernetes1.24中的变化
Lamp platform deployment and Application









