使用html2canvas 截图 样式全崩。 为什么啊
下面是截图,左边是截图的结果,右边是网页展示的原内容。
const downLoad = async () => {
const dom2 = document.getElementById('share-card');
console.log(dom2, 'dom');
setTimeout(() => {
html2canvas(dom2, {
useCORS: false,
height: 400,
width: 750,
scrollY: 0,
scrollX: 0,
allowTaint: false,
onclone: (doc) => {
doc.querySelectorAll('script').forEach(script => script.remove());
console.log("克隆后的 DOM 结构:", doc.documentElement.innerHTML);
}
}).then(canvas => {
// 将生成的 Canvas 显示在页面上
const link = document.createElement('a');
link.download = 'screenshot2222.png';
link.href = canvas.toDataURL('image/png');
link.click();
});
},1000)