通过a标签,下载图片
代码
// 图片下载
onDownload(filepath, filename) {
const x = new XMLHttpRequest()
x.open('GET', filepath, true)
x.responseType = 'blob'
x.onload = function () {
const blob = x.response
const url = window.URL.createObjectURL(blob)
// 判断是否是IE浏览器
if (window.navigator.msSaveBlob) {
try {
window.navigator.msSaveBlob(blob, filename)
} catch (e) {
}
} else {
const a = document.createElement('a')
a.href = url
a.download = filename
a.click()
}
}
x.send()
},