1.前端Vue
(注意:调用后端接口时需指定{responseType:'blob'},否则导出的excel表格打不开)
//Vue导出方法
exportExcel(){
//searchParam:为前端需传到后端的所需参数
var searchParam = {
test:this.data.test,
};
//调用后端接口,传入参数searchParam
//注意:调用后端接口时需指定{responseType:'blob'},否则导出的excel表格打不开
request.post("/exceltest/exportExcel",searchParam,{responseType:'blob'}).then((res) => {
const aLink = document.createElement('a')
//为Blob指定导出的文件类型,此处为xlsx[{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}]
var blob = new Blob([res.data], {type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"})
// //从response的headers中获取filename, 后端response.setH