截图dom html2canvas使用文档 setup

1 安装

npm install --save html2canvas

yarn add html2canvas

2 demo 引入

import html2canvas from 'html2canvas';

 demo   会直接下载div ref =picture  里面的内容

中间内容可忽视 

 <div ref="picture">
            <div class="flex text-[20px] text-[#333] justify-center items-center flex-col">
              <a-input class="!w-[300px]" readonly :value="copyCourseShareText" />
            </div>

            <div id="codeImg" class="code-img">
              <Image :src="qrcode" class="" />
              <!-- <div> <Image :src="getFocusCompany.logo" alt="" class="centrale-img" /> </div> -->
            </div>
          </div>

js

 const picture = ref() 
 // 生成图片
  const creatImg = () => {
    const setup = {
      useCORS: true // 使用跨域
    }
    html2canvas(picture.value, setup).then(canvas => {
      const link = canvas.toDataURL('image/jpg')
      exportPicture(link, '分享課程')
    })
  }

  // 导出图片
  const exportPicture = (link, name = '未命名文件') => {
    const file = document.createElement('a')
    file.style.display = 'none'
    file.href = link
    file.download = decodeURI(name)
    document.body.appendChild(file)
    file.click()
    document.body.removeChild(file)
  }

插件bug

这个bug是

省略两行 效果 变成了  最后一行字消失了3分1 且没有省略号 

有想过用绝对定位并且+省略号和空白底   但是会因为文本的内容不确定性 有可能会遮住半个字

所以需要这个效果 就只能换个插件了(有找到解决方法可反馈)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值