/**
* 外部传入参数
* hurl 下载地址
* fileName 下载文件的名称
*/
let that = this;
var xhr = new XMLHttpRequest();
xhr.open('GET', hurl,true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.responseType = "blob";
// xhr.onprogress = function (event) {
// 可监听文件下载进度
// console.log(xhr)
// debugger
// if (event.lengthComputable) {
// debugger
// console.log(event.loaded);
// console.log(event.total);
// }
// };
xhr.onload = function (oEvent) {
if (xhr.readyState === 4 && xhr.status === 200) {
// var name = xhr.getResponseHeader("Content-disposition");
// var filename = name.substring(20,name.length);
var blob = new Blob([response]);
var csvUrl = URL.createObjectURL(blob);
var link = document.createElement('a');
link.href = csvUrl;
link.download = fileName;
link.click();
this.loading = false;
}
}
xhr.send();
js 实现文件流下载,文件下载进度监听
最新推荐文章于 2024-04-03 11:30:17 发布