wangEditor编辑器 Vue基本配置项

1.Vue安装方法

npm i wangeditor -S

<template>
<div id='wangeditor'>
<div id="editor">
<!-- <p>欢迎使用 <b>wangEditor</b> 富文本编辑器</p> -->
</div>
<button @click="updata">提交啊</button>
</div>
</template> <script>
import E from "wangEditor";
import 'wangeditor/release/wangEditor.min.css'
// wangEditor配置按钮菜单
const btnmenu = [
'head',//标题
'bold',//粗体
'fontSize',//字号
'fontName',//字体
'italic',//斜体
'undeline',//下划线
'strikeThrough',//删除线
'foreColor',//文字颜色
'backColor',//背景颜色
'link',//插入链接
'list',//列表
'justify',//对齐方式
'quote',//引用
'emoticon',//表情
'image',//插入图片
'table',//表格
'video',//插入视频
'code',//插入代码
'undo', //撤销
'redo', // 重复
]
export default {
name:'wangeditor',
// model:{
// prop:'value',
// event:'change',
// },
// props:{
// value:{
// type:String,
// default:''
// },
// isClear:{
// type:Boolean,
// default:''
// }
// },
data() {
return {
exconten:'',
editor:'',
info:'',
}
},
mounted(){ this.editor = new E('#editor');
// 自定义菜单配置
this.editor.customConfig.menus = btnmenu;
// 配置上传图片为base64
this.editor.customConfig.uploadImgShowBase64=false;
// 配置图片上传服务器
this.editor.customConfig.uploadImgServer='/upload';
// 隐藏“网络图片”tab
this.editor.customConfig.showLinkImg = false
// withCredentials(跨域传递 cookie)
this.editor.customConfig.withCredentials = true;
// 自定义header
this.editor.customConfig.uploadHeader={};
// 后端接收上传文件的参数名
this.editor.customConfig.uploadFileName='';
// 将图片大小限制为2M
this.editor.customConfig.uploadImgMaxSize=2*1024*1024;
// 限制最多上传6张图片
this.editor.customConfig.uploadImgMaxLength=6;
// 设置超时
this.editor.customConfig.uploadImgTimeout=3*60*1000;
// 关闭粘贴样式的过滤
this.editor.customConfig.pasteFilterStyle = false;
// 忽略粘贴内容中的图片
this.editor.customConfig.pasteIgnoreImg = true;
// 自定义处理粘贴的文本内容
this.editor.customConfig.pasteTextHandle = function (content) {
// content 即粘贴过来的内容(html 或 纯文本),可进行自定义处理然后返回
// return content + '<p>在粘贴内容后面追加一行</p>'
return content;
}
// url 即插入图片的地址(插入网络图片的回调)
this.editor.customConfig.linkImgCallback = function (url) {
console.log(url)
}
// 插入链接的校验
this.editor.customConfig.linkCheck = function (text, link) {
console.log(text) // 插入的文字
console.log(link) // 插入的链接
return true // 返回 true 表示校验成功
// return '验证失败' // 返回字符串,即校验失败的提示信息
}
// 插入网络图片的校验
this.editor.customConfig.linkImgCheck = function (src) {
console.log(src) // 图片的链接
return true // 返回 true 表示校验成功
// return '验证失败' // 返回字符串,即校验失败的提示信息
}
// 创建富文本编辑器
this.editor.create()
// 获取富文本内容
this.editor.txt.html();
// 编辑区域的z-index默认为100
this.editor.customConfig.zIndex = 100;
// 图片上传回调
this.editor.customConfig.uploadImgHooks={
fail:(xhr,editor,result)=>{/**插入图片回调失败 */},
success:(xhr,editor,result)=>{/**图片上传成功回调 */},
timeout:(xhr,editor,result)=>{/**网络超时回调 */},
error:(xhr,editor,result)=>{/**图片上传错误回调 */},
customInsert:(insertImg,result,editor)=>{/**图片上传成功,插入图片回调 */}
}
// 上传图片的错误提示默认使用alert弹出,你也可以自定义用户体验更好的提示方式
this.editor.customConfig.customAlert = function (info) {
// info 是需要提示的内容
alert('自定义提示:' + info);
console.log(info);
}
this.editor.customConfig.customUploadImg = function (files, insert) {
// files 是 input 中选中的文件列表
// insert 是获取图片 url 后,插入到编辑器的方法 // 上传代码返回结果之后,将图片插入到编辑器中
insert(imgUrl)
}
// 监听实时富文本输入内容
// this.editor.customConfig.onchange=(html)={
// let info=html;
// this.$emit('change',info);
// }
},
methods:{
updata(){
alert(this.editor.txt.html());
this.editor.txt.html('');
}
},
// watch:{
// isClear(val){
// // 触发清除文本域内容
// if(val){
// this.editor.txt.clear();
// this.info = '';
// }
// },
// value(val){
// // 使用v-model时,设置初始值
// this.editor.txt.html(val);
// }
// }
}
</script> <style> </style>

  

wangEditor编辑器 Vue基本配置项的更多相关文章

  1. Java web 引入wangEditor编辑器

    最近项目需要我做些前端的事,这让我这个半吊子前端很是痛苦.项目中需要一个编辑器,之前找了个ueditor,插件比较多,需要改源码等等不说,最后弄好了,发现需要flash插件.没办法,只有推到重来,在网 ...

  2. PHP UEditor富文本编辑器 显示 后端配置项没有正常加载,上传插件不能正常使用

    UEditor是由百度web前端研发部开发所见即所得富文本web编辑器,具有轻量,可定制,注重用户体验等特点,开源基于MIT协议,允许自由使用和修改代码... 问题描述 我的编辑器在本地测试的时候没问 ...

  3. 修改vue的配置项支持生产环境下二级目录访问的方法

    本文主要记录如何配置vue的打包文件配置项,使打包后的文件可以支持二级目录的访问. 1.常规打包 在实际的项目中,我们通常都使用 npm run build 直接打包文件后丢到服务器上访问 打包后的文 ...

  4. wangEditor编辑器中解析html图文信息问题

    在JS中,有一种方法:innerHTML 属性设置或返回表格行的开始和结束标签之间的 HTML. 也就是说,我们可以利用这个属性,把字符串转换为html代码,这样就可以被解析了. 其次,我们是需要在页 ...

  5. 集成百度编辑器 ueditor 后端配置项没有正常加载,上传插件不能正常使用!

    项目要用到编辑器,于是集成了ueditor,集成ok,但一直显示 ‘’后端配置项没有正常加载,上传插件不能正常使用!‘’ 各种查: 网上说的无非就是那么集中情况 1. 因为百度官方的问题,php/co ...

  6. 前端富文本编辑器vue + tinymce

    之前有项目需要用到富文本编辑器,在网上找了好几个后,最终选择了这个功能强大,扩展性强的tinymce tinymce中文文档地址(不全):http://tinymce.ax-z.cn/ tinymce ...

  7. vue 函数配置项watch以及函数 $watch 源码分享

    Vue双向榜单的原理     大家都知道Vue采用的是MVVM的设计模式,采用数据驱动实现双向绑定,不明白双向绑定原理的需要先补充双向绑定的知识,在watch的处理中将运用到Vue的双向榜单原理,所以 ...

  8. wangEditor编辑器控件里textarea的id不要用content

    头引用 <script type="text/javascript" src="js/jquery-1.10.2.min.js"></scri ...

  9. 一款好用的wangEditor编辑器

    文档:https://www.kancloud.cn/wangfupeng/wangeditor3/332599

随机推荐

  1. DDoS攻击与防御(3)

    3.攻击应用资源网络应用和服务在处理数据时,通常需要消耗一定的网络连接.计算和存储资源,这些资源是由应用程序向系统进行申请并自行管理和维护的.消耗应用资源的DDoS攻击就是通过向应用提交大量消耗资源的 ...

  2. React(v16.8.4)生命周期详解

    当前版本v16.8.4 装载过程(组件第一次在DOM树中渲染的过程): constructor(常用) -> getInitialState(v16.0已废弃) -> getDefault ...

  3. echarts研究

    1.echarts是什么? 关键字:data visualization,canvas,chart Echarts是基于轻量级的canvas类库,纯javaScript实现,MVC封装,数据驱动,一款 ...

  4. CSS3常用

    1.user-select新增特性,主流浏览器都支持 -webkit-user-select: none;  /* Chrome all / Safari all /opera15+*/  -moz- ...

  5. ECMA Script 6_RegExp 正则表达式

    在 ES5 中 RegExp 构造函数的参数有两种情况 RegExp(字符串, 正则表达式的修饰符) RegExp(正则表达式); var regex = new RegExp('xyz', 'i') ...

  6. margin-bottom在safari浏览器失效的问题

    今天遇到一个bug是底部明明有margin-bottom却无法作用,排查了一下改成用padding可以有效 但不找出原因是无法完成这篇博客的 问题概要描述:在safari中,当内容高度超出所有父容器时 ...

  7. HTML列表与表格

    border:控制边框 width:宽度 height:高度 table是表格 tr:行 td:列★ colspan:合并列★rowspan:合并行★ <!doctype html> &l ...

  8. ThinkPHP5 添加多个文字水印及疑难解答

    public function imageload() { $imgpath = ROOT_PATH . 'public' . DS . 'static' . DS . 'www' . DS . 'i ...

  9. PAT甲级1123 Is It a Complete AVL Tree【AVL树】

    题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805351302414336 题意: 给定n个树,依次插入一棵AVL ...

  10. Linux 的 date 日期的使用

    解决的问题有: 1:查看当前日期和时间 2:查看前几天的日期,或者后几天的日期. 3:查看上周几的日期,或者下周几的日期. 4:查看前后几小时,分钟.时间 编写一个简单的shell: 输出下个星期二的 ...