export function downLoadImage(url) {
let x = new XMLHttpRequest()
let resourceUrl = url
let name = url.split('/').slice(-1)[0].split('.')[0]
x.open('GET', resourceUrl, true)
x.responseType = 'blob'
x.onload = e => {
// ie10+
if (navigator.msSaveBlob) {
let name = resourceUrl.substr(resourceUrl.lastIndexOf('/') + 1)
return navigator.msSaveBlob(x.response, name)
} else {
let url = window.URL.createObjectURL(x.response)
let a = document.createElement('a')
a.href = url
a.download = name //保存的文件名称
a.click()
}
}
x.send()
}
window.URL.revokeObjectURL(url)
最后得使用window.URL.revokeObjectURL(url)减少内存占用。