后台返回excel文件流,js下载

  /** 下载excel */
  downloadExcel(data: Blob): void {
    var blob = new Blob([data], { type: 'application/vnd.ms-excel    application/x-excel;charset=utf-8' }); // application/vnd.openxmlformats-officedocument.spreadsheetml.sheet这里表示xlsx类型
    var downloadElement = document.createElement('a');
    var href = window.URL.createObjectURL(blob);
    downloadElement.href = href;
    downloadElement.download = '传染病报告卡待填报导出.xls';
    document.body.appendChild(downloadElement);
    downloadElement.click();
    document.body.removeChild(downloadElement);
    window.URL.revokeObjectURL(href);
  }

记得请求的responsType: 'blob'

上一篇:javascript 模拟用户点击实现文件下载


下一篇:后台传来的流文件,前端如何实现文件下载