1,发送post请求,携带表单参数,加上响应类型:responseType:'blob'
export const exportExcel = params => {return axios.post(`/test/export`, params,{responseType:'blob'}); };
2,处理二进制流,生成excel表格
exportExcel (this.filters).then((res)=>{
const blob =new Blob([res.data], {type:'application/octet-stream;charset=utf-8'});
const fileName ='测试.xlsx';
const elink =document.createElement('a');
elink.download =fileName;
elink.style.display ='none';
elink.href =URL.createObjectURL(blob);
document.body.appendChild(elink);
elink.click();
URL.revokeObjectURL(elink.href);
document.body.removeChild(elink);
}).catch((error)=>{
this.$message({
message: error,
type:'error'
});
})
网友评论