前端:
1.导入ajax.js
import request from '@/plugin/ajax.js'
2.接口使用
有api文件
const TestExcelDonation = function (params) {//导出Excel
return request({
url: `${prefixerForProxy}/Test/QueryToExcel`,
method: 'get',
headers: {
'Content-Type': 'multipart/form-data;charset=UTF-8'
},
responseType: 'blob', //二进制流
params
})
}
文件下载:
api.TestExcelDonation().then(res=>{
const blob = new Blob([res.data]);
saveAs(blob, "Test.xls");
})
后端:
public ActionResult QueryToExcel(QueryDonationModel para)
{
//路径
var path = _test.QueryToExcel(para);
return File(new FileStream(path, FileMode.Open), "application/octet-stream", "资金捐赠台账.xls");
}