vue3 富文本wangEditor

 

 onMounted(() => {

      instance = new WangEditor(editor.value);

      instance.config.showLinkImg = false;

      instance.config.showLinkImgAlt = false;

      instance.config.showLinkImgHref = false;

      instance.config.uploadImgMaxSize = 2 * 1024 * 1024; // 2M

      instance.config.uploadFileName = "file";

      instance.config.uploadImgHeaders = {

        token: state.token

      };

      // 图片返回格式不同,需要自定义返回格式

      instance.config.uploadImgHooks = {

        // 图片上传并返回了结果,想要自己把图片插入到编辑器中

        // 例如服务器端返回的不是 { errno: 0, data: [...] } 这种格式,可使用 customInsert

        customInsert: function(insertImgFn, result) {

          console.log("result", result);

          // result 即服务端返回的接口

          // insertImgFn 可把图片插入到编辑器,传入图片 src ,执行函数即可

          if (result.data && result.data.length) {

            result.data.forEach(item => insertImgFn(item));

          }

        }

      };

      instance.config.uploadImgServer = uploadImgsServer;

      Object.assign(instance.config, {

        onchange() {

          console.log("change");

        }

      });

      instance.create();

      if (id) {

        axios.get(`/goods/${id}`).then(res => {

          const { goods, firstCategory, secondCategory, thirdCategory } = res;

          state.goodForm = {

            goodsName: goods.goodsName,

            goodsIntro: goods.goodsIntro,

            originalPrice: goods.originalPrice,

            sellingPrice: goods.sellingPrice,

            stockNum: goods.stockNum,

            goodsSellStatus: String(goods.goodsSellStatus),

            goodsCoverImg: proxy.$filters.prefix(goods.goodsCoverImg),

            tag: goods.tag

          };

          state.categoryId = goods.goodsCategoryId;

          state.defaultCate = `${firstCategory.categoryName}/${secondCategory.categoryName}/${thirdCategory.categoryName}`;

          if (instance) {

            // 初始化商品详情 html

            instance.txt.html(goods.goodsDetailContent);

          }

        });

      }

    });

    onBeforeUnmount(() => {

      instance.destroy();

      instance = null;

    });

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值