1、设置请求参数
// 导出订单Excel
export const getOrderExcel = param => {
return request({
url: '/order/excel/',
method: 'get',
params: param,
responseType: 'blob',
headers: {
'Content-Type': 'application/x-download'
}
});
};
需要设置responseType和Content-Type
2、触发文件下载
getOrderExcel(query).then(res => {
console.log(res);
const link = document.createElement("a");
link.style.display = "none";
link.href = URL.createObjectURL(res);
link.setAttribute("download", "订单信息.xlsx");
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
})