废话不多写,定义data,封装http那些自行脑补,这里只写最关键的下载部分代码
文件流转换 window.URL.createObjectURL(response)
if(this.exportExcelLoading==false){
this.exportExcelLoading=true //避免重复请求的标识
$xh.http({
type: "get", //后端协商请求方式
responseType: "blob",
url: "SYS-outputDevice",//请求地址
params: para,//参数
})
.then(response => {
this.exportExcelLoading = false;
let url = window.URL.createObjectURL(response); //转换文件流未url
let link = document.createElement("a");
link.style.display = "none";
link.href = url;
link.setAttribute("download", "文件名.xls");
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
})
.catch(err => {
this.exportExcelLoading = false; //避免重复请求的标识
});
},
}