html2canvas截取图片并下载
let element = document.getElementById('pic') html2canvas(element).then(canvas => { let layer_pic = canvas.toDataURL('image/png') let byteCharacters = atob(layer_pic.split(',')[1]) let byteNumbers = new Array(byteCharacters.length) for (let i = 0; i < byteCharacters.length; i++) { byteNumbers[i] = byteCharacters.charCodeAt(i) } let byteArray = new Uint8Array(byteNumbers) let blob = new Blob([byteArray], { type: 'image/jpeg' }) let url = URL.createObjectURL(blob) let a = document.createElement('a') a.href = url a.download = 'JHDGap.jpg' a.click() URL.revokeObjectURL(url) return })