wangEditor富文本

6 篇文章 0 订阅
<div style="float: left; width: 70%; height: 570px">
            <div
              id="editor2"
              style="
                border: 1px solid #ccc;
                float: left;
                width: 100%;
                border-bottom: none;
                margin-top: 10px;
              "
            ></div>
            <div
              id="editor3"
              class="text"
              style="float: left; height: 500px; width: 100%"
            ></div>
          </div>
<script type="text/javascript" src="<%= BASE_URL %>wangEditor-3.1.1/release/wangEditor.min.js"></script>
editor: "", // 取值html this.editor.txt.html(); 赋值html this.editor.txt.html(值);



 mounted() {
    //富文本编辑框初始化
    const E = window.wangEditor;
    let editor2 = document.getElementById("editor2");
    let editor3 = document.getElementById("editor3");
    var editor = new E(editor2, editor3);
    editor.customConfig.pasteFilterStyle = false;
    editor.customConfig.pasteTextHandle = function (content) {
      //清除word文档粘贴过来的样式
      // content 即粘贴过来的内容(html 或 纯文本),可进行自定义处理然后返回
      if (content == "" && !content) return "";
      var str = content;
      str = str.replace(/<xml>[\s\S]*?<\/xml>/gi, "");
      str = str.replace(/<style>[\s\S]*?<\/style>/gi, "");
      str = str.replace(/<\/?[^>]*>/g, "");
      str = str.replace(/[ | ]*\n/g, "\n");
      str = str.replace(/&nbsp;/gi, "");
      return str;
    };
	//新版本将editor.customConfig.pasteFilterStyle = false;换成editor.config.pasteFilterStyle
    editor.customConfig.uploadImgShowBase64 = false; // 不使用 base64 保存图片
    editor.customConfig.uploadImgServer = "xxxxxxxxxx"; //上传图片地址
    editor.customConfig.uploadImgMaxSize = 2 * 1024 * 1024;
    editor.customConfig.uploadFileName = "img"; //上传图片名称
    editor.config.uploadImgHeaders = {//设置图片请求头
      Accept: 'text/x-json',
    }
    editor.customConfig.uploadImgHooks = {
    customInsert: function (insertImg, result, editor) {
                // 图片上传并返回结果,自定义插入图片的事件(而不是编辑器自动插入图片!!!)
                // insertImg 是插入图片的函数,editor 是编辑器对象,result 是服务器端返回的结果
         
                // 举例:假如上传图片成功后,服务器端返回的是 {url:'....'} 这种格式,即可这样插入图片:
                var url =result.data;
                insertImg(url);
         
                // result 必须是一个 JSON 格式字符串!!!否则报错
            }
        }
    editor.customConfig.menus = [
      //自定义菜单
      "head", //标题
      "bold", //粗体
      "italic", //斜体
      "underline", //下划线
      "strikeThrough", //删除线
      "foreColor", //文字颜色
      "backColor", //背景颜色
      "link", // 插入链接
      "list", // 列表
      "justify", //对齐方式
      "quote", //引用
      "emoticon", //表情
      "image", //插入图片
      "table", //表格
      // 'video',  //插入视频
      "code", //插入代码
      "undo", //撤销
      "redo", //重复
    ];
    editor.create();
    this.editor = editor;
  },



<style scoped="scoped">
/* 解决编辑框层级太高==》覆盖其他元素的问题 */
.w-e-menu {
  z-index: 1 !important;
}
.w-e-text-container {
  z-index: 1 !important;
}
/*  */
</style>

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值