// 截图
screenshotChange() {
var node = document.getElementById(‘goodsDetail’)
var width = node.offsetWidth
var height = node.offsetHeight
var scale = 2
const a = document.createElement(‘a’)
html2canvas(node, {
width: width,
heigth: height,
backgroundColor: ‘#ffffff’,
dpi: window.devicePixelRatio * 2,
scale: scale,
X: 0,
Y: 0,
useCORS: true,
allowTaint: true,
tainttest: true, // 检测每张图片都已经加载完成
logging: true
}).then(canvas => {
const capture = canvas.toDataURL(‘image/png’)
const saveInfo = {
download: moment().format(‘YYYY-MM-DD HH:mm:ss’) + .png
,
href: capture
}
this.downloadFile(saveInfo)
})
},
downloadFile(saveInfo) {
const element = document.createElement(‘a’)
element.style.display = ‘none’
for (const key in saveInfo) {
element.setAttribute(key, saveInfo[key])
}
document.body.appendChild(element)
element.click()
setTimeout(() => {
document.body.removeChild(element)
}, 300)
}
html2canvas 页面截图
最新推荐文章于 2024-03-18 16:07:20 发布