<script src="wangEditor/3.1.1/wangEditor.min.js"></script>
Vue.component('my-wangeditor', {
props: ['value'],
data() {
return {
flag: true,
editor: null,
}
},
watch: {
value(val) {
if(this.flag){
//这里初始化的时候赋值
this.editor.txt.html(val);
}
this.flag = true;
}
},
mounted: function () {
const self = this;
let E = window.wangEditor;
self.editor = new E(this.$refs.editorElem); //创建富文本实例
self.editor.customConfig.onchange = (html) => {
this.flag = false;//这里改变绝对不能触发初始化赋值 否者会出现问题
self.$emit('input', html);
};
self.editor.customConfig.uploadImgServer = '图片上传地址';
self.editor.customConfig.uploadFileName = 'file';
self.editor.customConfig.uploadImgMaxSize = 1024 * 1024;// 将图片大小限制为 1M
self.editor.customConfig.uploadImgMaxLength = 1;// 限制一次最多上传 1 张图片
self.editor.customConfig.uploadImgTimeout = 3 * 60 * 1000;// 设置超时时间
// editor.customConfig.uploadImgHeaders = {
// 'Accept': '*/*',
// 'Authorization':'Bearer ' + token //头部token
// };
self.editor.customConfig.menus = [ //菜单配置
'head', // 标题
'bold', // 粗体
'fontSize', // 字号
'fontName', // 字体
'italic', // 斜体
'underline', // 下划线
'strikeThrough', // 删除线
'foreColor', // 文字颜色
'backColor', // 背景颜色
'link', // 插入链接
'list', // 列表
'justify', // 对齐方式
'quote', // 引用
'emoticon', // 表情
'image', // 插入图片
'table', // 表格
'video', // 插入视频
// 'code', // 插入代码
'undo', // 撤销
'redo' // 重复
];
//下面是最重要的的方法
self.editor.customConfig.uploadImgHooks = {
before: function (xhr, editor, files) {
// 图片上传之前触发
// xhr 是 XMLHttpRequst 对象,editor 是编辑器对象,files 是选择的图片文件 // 如果返回的结果是 {prevent: true, msg: 'xxxx'} 则表示用户放弃上传
// return {
// prevent: true,
// msg: '放弃上传'
// }
},
success: function (xhr, editor, result) {
// 图片上传并返回结果,图片插入成功之后触发
// xhr 是 XMLHttpRequst 对象,editor 是编辑器对象,result 是服务器端返回的结果
self.imgUrl = Object.values(result.data).toString()
},
fail: function (xhr, editor, result) {
// 图片上传并返回结果,但图片插入错误时触发
// xhr 是 XMLHttpRequst 对象,editor 是编辑器对象,result 是服务器端返回的结果
},
error: function (xhr, editor) {
// 图片上传出错时触发
// xhr 是 XMLHttpRequst 对象,editor 是编辑器对象
},
timeout: function (xhr, editor) {
// 图片上传超时时触发
// xhr 是 XMLHttpRequst 对象,editor 是编辑器对象
}, // 如果服务器端返回的不是 {errno:0, data: [...]} 这种格式,可使用该配置
// (但是,服务器端返回的必须是一个 JSON 格式字符串!!!否则会报错)
customInsert: function (insertImg, result, editor) {
// 图片上传并返回结果,自定义插入图片的事件(而不是编辑器自动插入图片!!!)
// insertImg 是插入图片的函数,editor 是编辑器对象,result 是服务器端返回的结果 // 举例:假如上传图片成功后,服务器端返回的是 {url:'....'} 这种格式,即可这样插入图片:
// let url = Object.values(result.data); //result.data就是服务器返回的图片名字和链接
// JSON.stringify(url); //在这里转成JSON格式
insertImg(result.data.location);
// result 必须是一个 JSON 格式字符串!!!否则报错
}
};
self.editor.create();
},
methods: { },
updated() { },
created() { },
destroyed() { },
template: '<div id="wangeditor"><div ref="editorElem" v-model="value" style="text-align:left"></div></div>'
});
使用方法
<my-wangeditor v-model="notes"></my-wangeditor>

vue wangeditor3封装的更多相关文章

  1. vue+elementUI封装的时间插件(有起始时间不能大于结束时间的验证)

    vue+elementUI封装的时间插件(有起始时间不能大于结束时间的验证): html: <el-form-item label="活动时间" required> & ...

  2. vue如何封装自己需要的方法

    因为现在vue的流行,vue的各种插件都出来了,我们公司也是使用vue做项目,我自己在做项目的时候自己去琢磨了其他的插件以及结合自己对vue和es2015的理解,自己找的了一种在vue中使用封装方法的 ...

  3. vue axios封装以及登录token过期跳转问题

    Axios配置JWT/封装插件/发送表单数据 首先请务必已仔细阅读 Axios 文档并熟悉 JWT: 中文文档 JWT 中文文档 安装 npm install axios npm install es ...

  4. vue axios 封装(二)

    封装二: http.js import axios from 'axios' import storeHelper from './localstorageHelper' // 全局设置 const ...

  5. vue Axios 封装与配置项

    import axios from "axios"; import qs from "qs"; import { Message } from "el ...

  6. vue todolist 封装localstorage

    //封装操作localstorage本地存储的方法 模块化的文件 // nodejs 基础 var storage={ set(key,value){ localStorage.setItem(key ...

  7. vue中封装axios方法

    axios基本配置 使用方法 import axios from 'axios' // 创建axios实例 const service = axios.create({ baseURL: proces ...

  8. Vue 数组封装和组件data定义为函数一些猜测

     数组封装 var vm={ list:[0,1] } var push=vm.list.push;//把数组原来的方法存起来 vm.list.push=function(arg){//重新定义数组的 ...

  9. Vue如何封装多个全局过滤器到一个文件

    #### 在写vue项目时,所用的过滤器很多时,把所有的过滤器方法封装在一个文件中,然后导出,并绑定在vue实例上 1.在src下创建filters文件夹,并新建index.js文件 2. index ...

随机推荐

  1. 【转载】webDriver拾级而上·之五 iframe的处理

    有时候我们在定位一个页面元素的时候发现一直定位不了,反复检查自己写的定位器没有任何问题,代码也没有任何问题.这时你就要看一下这个页面元素是否在一个iframe中,这可能就是找不到的原因之一. 如果你在 ...

  2. 常见的http错误

    错误类型: 1xx(临时响应) 表示临时响应并需要请求者继续执行操作的状态代码. 2xx (成功) 表示成功处理了请求的状态代码. 3xx (重定向) 表示要完成请求,需要进一步操作. 通常,这些状态 ...

  3. maven工程运行演示

    通过maven提供的命令来运行maven工程,体会maven构建工程的优点. (1)运行web工程    进入maven工程目录(当前目录有pom.xml),运行tomcat:run命令 可能出现的问 ...

  4. h5-360_introduce页面案例

    整个网页的html 首先,忽略我的网页比较丑,主要是ps功底不太好, 其次这个网页是利用了全屏插件:jquery.fullPage.js.需要事先导入相应的js文件 js文件下载地址:http://w ...

  5. JVM源码分析之自定义类加载器如何拉长YGC

    概述 本文重点讲述毕玄大师在其公众号上发的一个GC问题一个jstack/jmap等不能用的case,对于毕大师那篇文章,题目上没有提到GC的那个问题,不过进入到文章里可以看到,既然文章提到了jstac ...

  6. i春秋-web-爆破3

    首先,是PHP代码审计,看懂就能解出来题. <?php error_reporting(0); session_start(); require('./flag.php'); if(!isset ...

  7. PAT Advanced 1013 Battle Over Cities (25) [图的遍历,统计连通分量的个数,DFS,BFS,并查集]

    题目 It is vitally important to have all the cities connected by highways in a war. If a city is occup ...

  8. 冒泡排序_python

    def popdata(ls): for i in range(len(ls)): for j in range(i+1,len(ls)): if ls[i]>ls[j]: # tmp=ls[i ...

  9. git登录账号密码错误remote: Incorrect username or password (access token)

    git提交时弹框让输入用户和密码,不小心输入错误了 再次提交 一直就提示  remote: Incorrect username or password 错误了,也不弹框要重新输入 解决方法 win1 ...

  10. 使用AJAX(阿贾克斯)创建级联菜单

    1. html页面 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> < ...