使用axios下载压缩包的时候;
axios设置:
return {
types: [COMMON_SUCCESS, COMMON_ERROR],
promise: axios.get(`${base}/service_mana/customer/downLoadZip`, {params: option, responseType: 'blob', headers: {Accept: 'application/vnd.openxmlformats-officedocument'}})
};
请求回来的流的处理:
const blob = new Blob([res.res.data], {type: 'application/zip'});
const filename = res.res.headers['content-disposition'];
const downloadElement = document.createElement('a');
const href = window.URL.createObjectURL(blob); //创建下载的链接
downloadElement.href = href;
[downloadElement.download] = [filename.split('=')[1]];
document.body.appendChild(downloadElement);
downloadElement.click(); //点击下载
document.body.removeChild(downloadElement); //下载完成移除元素
window.URL.revokeObjectURL(href); //释放blob对象