可以先創建一個a
標籤,然後設置download
屬性和href
屬性,之後點擊即可
this.selectedRowKeys.forEach((element) => {
let file = this.getFilename(element)[0];
let filename = file.fileName; // 文件名
let suffix = ""; // 後綴
try {
suffix = file.path.split(".")[1];
} catch {
suffix = "";
}
let link = document.createElement("a"); // 創建a標籤
if (suffix === "") { // 設置download屬性
link.download = filename;
} else {
link.download = filename + "." + suffix;
}
link.href = "/api/user/download?file_id="+element; // 設置 href屬性
console.log(link)
link.click(); // 點擊即可下載
link.remove(); // 刪除該節點