<div id="targetHtml">
1234
</div>
let element = document.querySelector("#targetHtml");
let imgWidth = element.offsetWidth;
let imgHeight = element.offsetHeight;
window.pageYOffset = 0;
document.body.scrollTop = document.documentElement.scrollTop = 0;
let configObj = {
allowTaint: true,
useCORS: true,
tainttest: true,
logging: true,
scale: 2,
dpi: 300,
width: imgWidth,
height: imgHeight,
backgroundColor: 'rgba(255,255,255,1)',
};
html2canvas(element, configObj).then((canvas) => {
console.log(canvas, 'can')
let imgUrl = canvas.toDataURL("image/jpeg");
const aDom = document.createElement('a')
aDom.href = imgUrl
aDom.download = new Date().valueOf() + '.png'
aDom.click()
});