vue使用html2canvas页面截图

由于项目需要页面截图功能,我就找到了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图片,大功告成。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。