接收并下载后端返回的文件
2021-08-05 本文已影响0人
安北分享
downloadError(){
console.log('++++++++++++++++++++')
// this.$http.post('api/exportFailCustomers',this.filCustomers)
this.$http({
method:"post",
url:"api/exportFailCustomers",
responseType:"blob",
data:{
customers: this.filCustomers
}
})
.then(res =>{
if(res.data.type){
const blob = new Blob([res.data],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});
let link = document.createElement("a");
link.href=URL.createObjectURL(blob);
link.setAttribute("download","失败数据.xlsx");
link.click();
link=null
this.$Message.success("下载成功");
}else{
this.$Message.error("下载失败")
}
})
.catch(err => {
this.$Message.error("下载失败")
})
},