获取后端返回的文件流下载文件至本地
function downloadFile (fileUrl) {
const xhr = new XMLHttpRequest();
xhr.open("get", fileUrl, true);
xhr.responseType = "blob";
xhr.send();
xhr.onload = function () {
let blob = this.response;
let url = window.URL || window.webkitURL;
let fileName = `文件名.xxx`;
let elink = document.createElement("a");
elink.download = fileName;
elink.style.display = "none";
elink.href = url.createObjectURL(blob);
document.body.appendChild(elink);
elink.click();
url.revokeObjectURL(elink.href);
document.body.removeChild(elink);
}
}