美文网首页
vue中发送axios请求导出excel表格

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

作者: 有梦想永远年轻 | 来源:发表于2019-03-29 13:30 被阅读0次

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'

    });

})

相关文章

网友评论

      本文标题:vue中发送axios请求导出excel表格

      本文链接:https://www.haomeiwen.com/subject/ihdlbqtx.html