vue 后端post请求返回二进制文件流 本地进行下载
参考代码如下
function exportData(res) {
let url = window.URL.createObjectURL(new Blob([res], { type: '.xlsx' }));
let a= document.createElement('a');
a.style.display = 'none';
a.href = url;
a.setAttribute('download', `数据统计报表.xlsx`);
document.body.appendChild(a);
a.click();
url = window.URL.revokeObjectURL(url);
document.body.removeChild(a)
}
//导出文件
export async function microApptaskExport(param) {
axios.defaults.headers["Authorization"] = `Bearer 用户token`;
axios.defaults.headers['Content-type']='application/json;';
const res = await axios.post(
"请求地址",
param,
{
responseType: "blob",
}
);
if (res) {
exportData(res);
}
}