post方式导出excel

众所周知, 若是导出excel等表格,大多是直接同过window.open(get请求地址)方式下载导出.

如果你走get是不带参数或者所携带的参数及它所对应的值很短的话可以使用这种方式.

但是万一所携带字符过长,就会导致字符丢失.这就需要post的方式进行.

不废话直接上代码.

第一步分装post导出方法,exportexcel

⒈设置请求时需要携带的请求头信息(例如token等),没有可不设.

第二部在需要的事件下进行调用


关键代码;

this.exportExcel(baseData,url).then(res => {             

// 处理返回的文件流

const blob = new Blob([res.data],{type: "application/vnd.ms-excel"});//,{type: 'application/vnd.ms-excel;charset=utf-8'}

let 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); // 释放URL 对象

document.body.removeChild(elink);

loading.close(); }) 

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

推荐阅读更多精彩内容