其他分享
首页 > 其他分享> > js下载流文件

js下载流文件

作者:互联网

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",
});
}
});



标签:文件,axios,url,res,js,exportExcel,data,下载
来源: https://www.cnblogs.com/evenbest/p/16697708.html