在通过Vue + iView + axios实现通过Blob下载Zip文件时,我遇到了一个问题,就是下载的Zip文件里面要么是空字符的的损坏文件,解压不出来,把Blob数据流打印出来发现乱码。
为了解决这个问题,我百度了许久,一直没有解决问题,网上的解决方法主要有如下几种:
(1)https://blog.csdn.net/hefeng6500/article/details/82988624博客中说axios请求中要设置"responseType: blob",告诉axios请求返回类型为blob;
axios({
method: 'POST',
url: '/api',
params: params,
responseType: 'blob'
}).then(res=>{
let blob = new Blob([res.data], {type: "application/vnd.ms-excel"});
let url = window.URL.createObjectURL(blob);
window.location.href = url;
}).catch(err=>{
console.log(err)
});
(2)在https://bl