Angular5 UI post 请求 输出 文件下载

  this.httpClient.post(url1, JSON.parse(data1) , {responseType: 'blob'}).subscribe(data => {
            const link = document.createElement('a');
            const blob = new Blob([data], {type: 'application/vnd.ms-excel'});
            link.setAttribute('href', window.URL.createObjectURL(blob));
            link.setAttribute('download', 'Inventory' + new Date().getTime() + '.xls');
            link.style.visibility = 'hidden';
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
        });
    }
View Code

猜你喜欢

转载自www.cnblogs.com/lshan/p/9810032.html
今日推荐