在请求头上加上:
responseType: 'blob'
bankBillmainexport() {
this.bankBillList = [];
this._spinner.show();
const params = {
current: this.current,
size: this.size,
doDataType: '4',
mainAccount: this.mainAccount,
mainNumber: this.mainNumber,
oppositeNumber: this.oppositeNumber,
oppositeName: this.oppositeName,
orderType:this.orderType
}
this._CaseAnalyzeService.bankBillmainexport(params).subscribe(
res => {
console.log('res:' + JSON.stringify(res));
this._spinner.hide();
const link = document.createElement('a'); //用a标签进行模拟下载
const blob = new Blob([res], {type: 'application/vnd.ms-excel'});
link.setAttribute('href', window.URL.createObjectURL(blob));
link.setAttribute('download', new Date().getTime() + '.xls');
link.style.visibility = 'hidden';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
},
error => {
console.log('fail:' + JSON.stringify(error));
this._spinner.hide();
}
);
}
欢迎关注我的微信公众号
搜索:前端优学。
or扫码:
获取更多更好更有深度的前端学习好文。