记录html2canvas页面截图

30次阅读

共计 497 个字符,预计需要花费 2 分钟才能阅读完成。

因为我的项目须要页面截图性能,我就找到了 html2canvas 插件

<div ref="shareDom">
<div class="exclude"><div>
<div>
<button @click="goShare()"> 分享 <button>

 js

async goShare(){
let dom = this.$refs["shareDom"];
const res = await html2canvas(dom, {
width: parseInt(window.getComputedStyle(dom).width),
height: parseInt(window.getComputedStyle(dom).height),
allowTaint: true,
taintTest: false,
scale: window.devicePixelRatio, 设施像素比
ignoreElements:(element)=>{可从渲染中删除匹配的元素
if(element.className === 'exclude') return true;
},
})
this.imgUrl = res.toDataURL()
}

最初就是一张 base64 图片。

正文完
 0