代码
async downloadFile(url) {
try {
if (true) {
// 构造要下载的文件URL
const fileUrl =""; // 替换为实际要下载的文件URL
var suffix = fileUrl.substring(fileUrl.lastIndexOf("."));
// 创建一个a标签
let response = await fetch(fileUrl);
// 内容转变成blob地址
let blob = await response.blob();
// 创建隐藏的可下载链接
let objectUrl = window.URL.createObjectURL(blob);
let a = document.createElement("a");
//地址
a.href = objectUrl;
//修改文件名
a.download = "文件名" + `${suffix}`;
// 触发点击
document.body.appendChild(a);
a.click();
//移除
setTimeout(() => document.body.removeChild(a), 1000);
}
} catch (error) {
console.error(error);
} finally {
}
},