文件批量下載
export const downloadFile = (url) => {
const iframe = document.createElement("iframe");
iframe.style.display = "none"; // 防止影響頁面
iframe.style.height = 0; // 防止影響頁面
iframe.src = url;
document.body.appendChild(iframe); // 這一行必須,iframe掛在到dom樹上纔會發請求
// 5分鐘之後刪除(onload方法對於下載鏈接不起作用,就先摳腳一下吧)
setTimeout(()=>{
iframe.remove();
}, 5 * 60 * 1000);
}
在將 herf做成一個數組在for循環中調用函數就可以了
關於單個文件下載
點擊按鈕單個下載
DownLoadExcel(sensorCommonId, time) {
var that = this;
// 創建隱藏的可下載鏈接
var eleLink = document.createElement('a');
var url=''+that.url';
eleLink.download = time+sensorCommonId;
eleLink.style.display = 'none';
// 字符內容轉變成blob地址
eleLink.href = url
// 觸發點擊
document.body.appendChild(eleLink);
eleLink.click();
// 然後移除
document.body.removeChild(eleLink);
},