需求:点击模块进行下载excel文件
1.后台这边返回给我的文件流,如下图:
现在我点击下载excel按钮 对后台请求数据
//这是我的请求接口 //我在axios封装的时候是传递了三个数据
export const downloadExcel = function(params) {
return post(
"/tms//downloadExcel", //url
{
params: params //请求参数
},
{ responseType: "arraybuffer" } //下载必须按这个格式进行转换
);
};
downloadExcel({
startDate: this.startTime,
endDate: this.endTime,
page: this.current,
pageSize: this.pageSize,
tradeNo: this.keyword,
patientsName: this.keyword,
doctorName: this.keyword,
hospitalDeptId: this.deptCode, //获取科室
allDataDownload: false
}).then(res => {
**//这里注意返回的数据,有的需要添加data(res.data)来进行获取 不然就会下载出来的excel文件是[object][object]**
const aLink = document.createElemen