vue下载excel文件接口返回乱码问题
一、背景post请求调用接口A下载excel文件不成功谷歌浏览器Network查看调用接口A的Preview:二、解决办法1.发送post请求时添加:responseType: 'blob'2.调用接口后添加:let blob = new Blob([res.data], { type: 'application/vnd.ms-excel' });let url = window.URL.crea
·
一、背景
- post请求
- 调用接口A
- 下载excel文件不成功
- 谷歌浏览器Network查看调用接口A的Preview:
二、解决办法
1.发送post请求时添加:responseType: 'blob'
2.调用接口后添加:
let blob = new Blob([res.data], { type: 'application/vnd.ms-excel' });
let url = window.URL.createObjectURL(blob);
window.location.href = url;
3.调用接口修改excle文件名或者后缀
let blob = new Blob([res.data], { type: 'application/vnd.ms-excel' });
let url = window.URL.createObjectURL(blob);
var filename = '修改的名字';
let link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.setAttribute('download', filename + '.xls')
document.body.appendChild(link)
link.click()
参考链接:
- https://blog.csdn.net/ic_xcc/article/details/103632618
- https://blog.csdn.net/hefeng6500/article/details/82988624?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase
更多推荐
已为社区贡献3条内容
所有评论(0)