//qrBase64是后台傳回來的base64數據
handleDownloadQrIMg(qrBase64) {
// 這里是獲取到的圖片base64編碼,這里只是個例子哈,要自行編碼圖片替換這里才能測試看到效果
const imgUrl = `data:image/png;base64,${qrBase64}`
// 如果瀏覽器支持msSaveOrOpenBlob方法(也就是使用IE瀏覽器的時候),那么調用該方法去下載圖片
if (window.navigator.msSaveOrOpenBlob) {
const bstr = atob(imgUrl.split(',')[1])
let n = bstr.length
const u8arr = new Uint8Array(n)
while (n--) {
u8arr[n] = bstr.charCodeAt(n)
}
const blob = new Blob([u8arr])
window.navigator.msSaveOrOpenBlob(blob, 'chart-download' + '.' + 'png')
} else {
// 這里就按照chrome等新版瀏覽器來處理
const a = document.createElement('a')
a.href = imgUrl
a.setAttribute('download', 'chart-download')
a.click()
}
}