- 原理:我們通過文件url地址,在瀏覽器回車就能下載。通過代碼模擬這個過程:js創建a標簽,然后js執行click事件。
//導出Excel
public async btnExport() {
let that = this as any;
this.loading = true;
let a = document.createElement('a');//創建a標簽
a.href = "http://www.abc.com/1/a.zip";//文件url或下載api
document.body.appendChild(a);
a.click();//觸發下載
document.body.removeChild(a);
setTimeout(async () => {
that.loading = false;
}, 4000);//4s后關閉loading,可以根據情況增減
}
