- 服务端给的一个下载接口:/order/exportOrderOpenInvoice
- 导出转化为Excel
const exportOrder= async()=>{
let reqData = {};
let exportOrderOpenInvoiceUrl = "/order/exportOrderOpenInvoice";
try {
const response = await axios.get(exportOrderOpenInvoiceUrl, {
params: reqData,
responseType: 'blob', //设定文件流 blob类型 (根据后端返回的类型设定)
});
if (response.data instanceof Blob) {
const downloadUrl = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = downloadUrl;
link.setAttribute('download', '导出的表格.xlsx');
document.body.appendChild(link);
link.click();
link.remove();
window.URL.revokeObjectURL(downloadUrl);
}
} catch (error) {
console.error('导出失败:', error);
message.error('导出失败');
}
}