const targetDom = document.getElementById('contract');
// 选项见文档:http://html2canvas.hertzen.com/configuration/
html2canvas(targetDom, {
allowTaint: true,
useCORS: true,
height: targetDom.clientHeight + targetDom.scrollTop + 40,
width: targetDom.clientWidth,
windowHeight: targetDom.clientHeight + targetDom.scrollTop + 40,
scale: 1
}).then((canvas) => {
// document.body.scrollTo({ x: 0, y: 0 });
let base64 = canvas.toDataURL('image/png');
console.log('dataURL', base64);
});
解决办法如上,windowHeight和Height中加上滚动条的高度。