前端根据后台返回url下载文件(图片、word、pdf)
getFileAndDownload(fileName, url) {
var x = new XMLHttpRequest()
x.open('GET', url, true)
x.responseType = 'blob'
x.onload = function(e) {
var blob = x.response
if ('msSaveOrOpenBlob' in navigator) {
// IE导出
window.navigator.msSaveOrOpenBlob(blob, fileName)
} else {
var a = document.createElement('a')
a.download = fileName
a.href = URL.createObjectURL(blob)
$('body').append(a)
a.click()
$(a).remove()
}
}
x.send()
},