1.需要将要转换成图片的区域div放置在body中,且需要display为block;
2.图片跨域的问题:将icon转换为base64
3.截图不全:新版本插件不稳定,建议
<script src="https://cdn.bootcss.com/html2canvas/0.5.0-alpha1/html2canvas.min.js"></script>
多尝试几个版本
document.querySelector("#slot").innerHTML = dom; document.querySelector("#share-module").style.display = "flex"; setTimeout(function(){ html2canvas(document.querySelector("#html2canvas"),{useCORS:true}).then(canvas => { document.querySelector("#shareImg").src=canvas.toDataURL(); document.querySelector("#slot").innerHTML = ""; }); },10);
此处的dom为要截图的区域div;
来源:https://www.cnblogs.com/changyaoself/p/12449745.html