使用wangEditor富文本编辑器遇到的问题总结

版权声明: https://blog.csdn.net/lhjuejiang/article/details/84671518

怎么使用和安装我就不详细说了,文档写得很清楚,https://www.kancloud.cn/wangfupeng/wangeditor3/332599

1、当屏幕缩时,富文本编辑器的选项会被隐藏,如下图官网的demo:当屏幕变小时,菜单选项就超出了富文本编辑器的区域,撤回和恢复已经隐藏不见了

原因,如果我们检查代码就会发现,其实富文本编辑器使用了弹性盒模型(不懂的百度,推荐阮一峰大神的文章:http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html?%5E%25$),display:flex,所以知道了这个问题就简单了,我们知道,弹性盒模型,默认情况下,项目都排在一行上面,也即超出部分不换行:flex-wrap:nowrap ,所以我们只需要更改编辑器的默认值即可,即添加一条样式:flex-wrap:wrap

.w-e-toolbar{
  flex-wrap:wrap;
}

注意:有时候我们在vue组件内部更改默认样式不起作用,此时可以在全局试试就可以了,至于为什么,我暂时还没搞明白,如果您知道,欢迎评论区留言告知哦,在此先谢过

就这么简单,然后看图:完美!

问题2:上传图片到服务器中(可以使用base64格式的,但是如果图片过大,经过base64编译过后文件会很大,所以不建议哦)

我封装了一个函数,可以上传图片,可以动态获取内容,如下:

data(){
  return {
    editContent:''//存储富文本编辑器的内容
  }
},


methods:{
 wangEdit (id) {
      let editor = new E(id)
      editor.customConfig.onchange = (html) => {
        this.editContent = html//动态获取富文本编辑器的内容
      }
      editor.customConfig.uploadImgMaxSize = 3 * 1024 * 1024;
      editor.customConfig.uploadFileName = 'file[]'
      editor.customConfig.uploadImgServer = '/proxy/platform/photo.moreImgUpload'//换成后端给你的上传图片的接口
      editor.customConfig.uploadImgHooks = {
        before: function (xhr, editor, files) {
          let formdata=new FormData();
          for(let i=0;i<files.length;i++){
            let url = files[i];
            formdata.append('file[]', url)
          }
        },
        customInsert: function (insertImg, result, editor) {
          for(let i=0;i<result.data.length;i++){
            let url = result.data[i]
            insertImg(url)
          }
        }
      }
      editor.create()
    }
}


//使用:this.wangEdit(‘#edit’)

猜你喜欢

转载自blog.csdn.net/lhjuejiang/article/details/84671518