表格下载
// HTML部分
<el-button @click="downLoadTable">
//数据部分
data(){
return{
totalCount:0,
}
}
// JS部分
downLoadTable(){
this.loading=true;
let params={
chartType:"table",
currentPage:"1",
pageSize:"1000",
stringFlag:"1",
totalCount:'this.totalCount',
},
this.$api.download(params).then(res=>{
this.loading=false;
if(res.data){
let name=res.headers['content-disposition'];
let fileName=name.split('=')[1];
// 将二进制流转化为链接
let blob=new Blob([res.data],{type:'blobtype'});
let downloadElement=document.createElement('a');
let href=URL.createObjectURL(blob);
downloadElement.href=href;
downloadElement.download=fileName;
document.body.appendChild(downloadElement);
downloadElement.click();
document.body.removeChild(downloadElement);
window.URL.revokeObjectURL(href)
}
}).catch(err=>{
this.$message({
message:”下载失败表格,请稍后重试!",
type:"error",
showClose:true
})
})
}