axios 二进制流导出
axios 二进制流导出
axios({
url: 'http://xxx',
method:'get',
data:{},
headers:{
'ContentType': 'application/x-www-form-urlencoded',
},
responseType: 'blob',
}).then(res=>{
let blob = res.data,
dateTime = this.tool.date.format(new Date(),'yyyyMMdd'),
down_url = window.URL.createObjectURL(blob),
a = document.createElement('a');
a.download = dateTime + '.zip' ; //文件命名
a.href = down_url;
$("body").append(a);
a.click();
$(a).remove();
loading.close();
}).catch(err=>{
loading.close();
this.$message({type:'error',message:'下载失败'});
})