let fileName = '****';
downExcel(fileName).then(res => { // 请求下载接口
// 处理返回的文件流
const content = res;
const blob = new Blob([content]);
const fileName = "Excel文件名称" + ".xlsx";
if ("download" in document.createElement("a")) {
// 非IE下载
const 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); // 释放URL 对象
document.body.removeChild(elink);
} else {
// IE10+下载
navigator.msSaveBlob(blob, fileName);
}
});
// 走后台接口 获取文件流
export function downExcel(fileName) {
return request({
url:'**********?fileName=' + fileName,
method:'get',
headers: {
"Content-Type": "application/json;application/octet-stream"
},
responseType: "blob",
params:''
})
}