wangEditor 官网自定义上传事件:https://www.kancloud.cn/wangfupeng/wangeditor2/123689

声明:我用的wangEditor版本是2.1.23

 

js:

var editor = new wangEditor('div1');
// 普通的自定义菜单
editor.config.menus = [
          ···
]; // 上传图片 editor.config.uploadImgUrl = '***'; editor.config.uploadImgFileName = '***'; // 自定义load事件 editor.config.uploadImgFns.onload = function (resultText, xhr) { //不知道是不是因为后台没有返回error,我的图片上传只进入onload方法,我用的谷歌浏览器 // resultText 服务器端返回的text // xhr 是 xmlHttpRequest 对象,IE8、9中不支持 // 上传图片时,已经将图片的名字存在 editor.uploadImgOriginalName var originalName = editor1.uploadImgOriginalName || '';  if(resultText == '0'){ //这个判断取决于后端返回怎样的数据,针对个人情况修改 alert('图片上传失败'); } // 如果 resultText 是图片的url地址,可以这样插入图片: editor.command(null, 'insertHtml', '<img src="' + resultText + '" alt="' + originalName + '" style="max-width:100%;"/>'); //editor插入HTML
 //如果是vue懒加载的话需要加上data-src属性,否则会加载失败   
//editor.command(null, 'insertHtml', '<img data-src="'+ resultText + '" src="' + resultText + '" alt="' + originalName + '" style="max-width:100%;"/>'); //editor插入HTML

}; editor.create();

相关文章:

  • 2021-05-05
  • 2021-10-07
  • 2021-10-16
  • 2022-12-23
  • 2021-07-05
  • 2021-10-12
猜你喜欢
  • 2022-01-08
  • 2021-07-04
  • 2021-10-26
  • 2022-12-23
  • 2021-04-18
  • 2021-08-01
  • 2022-12-23
相关资源
相似解决方案