npm install js-file-download --save
npm install axios --save
import axios from "axios";
import fileDownload from "js-file-download";
export const exportExcel = (url:string, params:any) => {
return axios({
method: 'POST',
url: url,
data: params,
responseType: 'arraybuffer',
headers: {
'Content-Type': 'application/json;charset=utf-8',
}
});
};
exportExcel(`导出的接口`,{
{...导出的接口参数}
}).then((res:any) => {
if(res.data.byteLength!==0){
fileDownload(res.data,'文件.xls');
}else{
ElMessage({
message: "无法找到对应的文件!!!",
type: "warning",
});
}
});
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/289666.html