downloadFile(_fileUrl, filename) {
var xhr = new XMLHttpRequest();
//加载出错的事件
// xhr.addEventListener("error", uploadFail, false);
xhr.open("GET", _fileUrl);
//设置响应类型
xhr.responseType = 'blob';
xhr.onload = function (e) {
if (this.status === 200) {
// 截取掉'attachment;filename='
// var filename = xhr.getResponseHeader("Content-disposition").slice(20);
var blob = this.response;
var a = document.createElement('a');
var url = URL.createObjectURL(blob);
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
}
}
xhr.send();
},
07-05
2868
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-09
565
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
11-10
2291
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
03-27
232
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
02-22
51
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-29
1579
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交