文件导出与下载—直接上代码
getExportReport(parame).then((resData) => {
// this.download(resData.data);
let fileName = this.activeData.event +"结果";
const link = document.createElement("a");
let blob = new Blob([resData.data], {
type: "application/vnd.ms-excel",
}); //文件流处理
link.style.display = "none";
link.href = URL.createObjectURL(blob);
link.download = fileName;
document.body.appendChild(link);
link.click();
window.URL.revokeObjectURL(link.href);
document.body.removeChild(link);
});
除了这里—还有就是接口的地方:responseType: ‘blob’;
export const getExportReport = (params) => {
return request({
url: '/api/alarm/result/exportReport',
method: 'post',
responseType: 'blob',
data: params
})
}
在此记录!