使用blob二进制流的方式下载后台文件

//url请求地址,datas传给后台的参数,fileName文件名,format文件类型后缀名如.xls
 downLoadFile(url,datas,fileName,format){
  this.http.post(url, datas, { responseType: 'blob' }).subscribe((result:any)=>{
    
const link
= document.createElement('a');
    const blob = new Blob([result], { type: 'application/zip' }); link.setAttribute(
'href', window.URL.createObjectURL(blob)); link.setAttribute('download', fileName + format); link.style.visibility = 'hidden'; document.body.appendChild(link); link.click(); document.body.removeChild(link);
}) };

注:本实例在angular6框架下实现

参考:https://blog.csdn.net/shengandshu/article/details/81127279?utm_source=blogxgwz4

posted @ 2019-11-11 16:11  倒带_with  阅读(2789)  评论(0编辑  收藏  举报