现在只适配网页
<view class="canvas" id="myDiy" ref="imageWrapper">
import html2canvas from 'html2canvas'; // 当前vue文件引入html2canvas
<script>
const mydiy = this.$refs.imageWrapper.$el;
html2canvas(mydiy, {
backgroundColor: null,
useCORS: true, // 开启跨域配置
allowTaint: true, // 允许跨域图片
taintTest: true // 是否在渲染前测试图片
}).then((canvas) => {
let dataURL = canvas.toDataURL('image/png');
console.log(dataURL);
console.log('网页截图');
// 创建一个链接
let a = document.createElement('a');
a.href = dataURL;
a.download = 'screenshot.png'; // 设置下载文件名
document.body.appendChild(a);
// 模拟点击链接进行下载
a.click();
// 移除链接
document.body.removeChild(a);
});
</script>