vue中发送axios请求导出excel表格

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'

    });

})

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容