解决html2canvas生成图片慢的问题

 

// 主要看那个点击事件就行
<div
              class="textBox-right-board-group"
              v-for="item in screenList"
              :key="item.id"
            >
              <!-- 获取不同分辨率下的屏幕的展示的文字大小DPI: fontSize: getFontSize(item.resolutionRatio), -->
              <div
                :class="['borderContainer', 'box' + item.id]"
                :style="{
                  width: changeResolutionRatio(item.resolutionRatio, 'width'),
                  height: changeResolutionRatio(item.resolutionRatio, 'height'),
                }"
                @click="
                  getDivImg('.box' + item.id, {
                    width: changeResolutionRatio(item.resolutionRatio, 'width'),
                    height: changeResolutionRatio(
                      item.resolutionRatio,
                      'height',
                    ),
                  })
                "
              ></div>
              <span> {{ item.resolutionRatio | changeResolutionRatio }} </span>
            </div>



    getDivImg(dom, obj) {
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      });

      const element = document.querySelector(dom);
      html2canvas(element, {
        useCORS: true,
        scale: 2,
        quality: 0.7,
        // 忽略无用节点(主要是这个)
        ignoreElements: e => {
          if (
            e.contains(element) ||
            element.contains(e) ||
            e.tagName === 'STYLE' ||
            e.tagName === 'LINK' ||
            e.getAttribute('data-html2canvas') != null // header里面的样式不能筛掉
          ) {
            console.log(e);
            return false;
          }
          // console.log(e.tagName);
          return true;
        }
      })
        .then((canvas) => {
          this.imgUrl = canvas.toDataURL("image/png");
        })
        .finally(() => {
          const enlargeScale = 2;
          function getPxValue(value) {
            const index = value.indexOf("px");
            return index !== -1 ? value.substring(0, index) : value;
          }
          this.dialogImgWH = {
            width: getPxValue(obj.width) * enlargeScale + "px",
            height: getPxValue(obj.height) * enlargeScale + "px",
          };
          loading.close();
          this.dialogVisible = true;
        });
    },




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值