-
正确格式
![]()
-
错误格式
![]()
-
请求方法
this.axios.get("api/xxx/xxx",{params:this.filter,responseType:'blob'})//这里的传递要加responseType:'blob'指定类型,后端不需要处理这个类型,只需要传过去就行 -
下载文件
.then((res)=>{
let blob=new Blob([res.data],{type:res.data.type})
//兼容ie
if(window.navigator && window.navigator.msSaveBlob){
window.navigator.msSaveBlob(blob,filename);
}else{
var downloadElement=document.createElement('a');//模拟一个a标签与asp.net试图操作类似
var href=window.URL.createObjectURL(blob);//转成链接让其能供人下载
downloadElement.href=href;//a标签的href
downloadElement.download=filename;//a标签的下载名字
document.body.appendChild(downloadElement);//注册这个控件将这个组件加到body尾部
downloadElement.click();//注销掉
window.URL.revokeObjectURL(href);//清除生成的链接,会占用一些东西,不知道啥,反正运行慢点
}
});
参考链接 https://blog.csdn.net/weixin_45973327/article/details/120565446


浙公网安备 33010602011771号