关于vue.js使用wangEditor3 基本设置和内容修改问题

由于项目中使用到了富文本编辑器,我刚好遇到了一系列的问题,编辑富文本的时候,出现富文本内容不能回显的问题,那说一下我的解决办法。

初次使用富文本是先安装富文本的插件:npm install wangeditor

官方文档https://www.kancloud.cn/wangfupeng/wangeditor3/335774,写的很简单,不过要仔细阅读。

<template>
    <div>
        <div ref="editor" style="text-align:left"></div>
        <button v-on:click="getContent">查看内容</button>
    </div>
</template>
 
<script>
    import E from 'wangeditor'
 
    export default {
      name: 'editor',
      data () {
        return {
          editorContent: ''
        }
      },
      methods: {
        getContent: function () {
            alert(this.editorContent)
        }
      },
      mounted() {
        var editor = new E(this.$refs.editor)
        editor.customConfig.onchange = (html) => {
          this.editorContent = html
        }
        editor.create()
      }
    }
</script>
 
<style scoped>
</style>

但是在父组件的时候是不能回显的,我根据查找资料发现原来是异步加载的原因导致我的附文本框内容没能及时回显出来,这个时候就需要用到监听watch来加载。

<template>
  <div>
    <div ref="editor" style="text-align:left"></div>
  </div>
</template>
 
<script>
import E from "wangeditor";
 
export default {
  name: "editor",
  data() {
    return {
      editor:""
    };
  },
  props: {
    content: { required: true }
  },
  mounted(){
    this.editor = new E(this.$refs.editor);
    
    this.editor.customConfig.onchange = html => {
 
      this.$emit('catchData',html);
 
    };
    // 配置服务器端地址
    this.editor.customConfig.uploadImgServer = "/Upload.php";
    //自定义一个图片参数名
    this.editor.customConfig.uploadFileName = "filename";
    // 将图片大小限制为 3M
    this.editor.customConfig.uploadImgMaxSize = 3 * 1024 * 1024;
 
    this.editor.create();
  },
  watch: {
     content: function(val) {
      this.editor.txt.html(val);
    }
  }
};
</script>
 
<style scoped>
</style>



原文链接:https://blog.csdn.net/u010585474/article/details/91555386

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值