h5 下载文件
需求
点击按钮, 进行下载文件
最开始使用这种方法, 但是会打开空白页
window.open("下载地址");
解决
注意: 目前发现不支持跨域链接
export function downloadFile(fileUrl, fileName = "") {
const a = document.createElement("a");
// 下载链接
a.setAttribute("href", fileUrl);
// 文件名, 为""时使用链接中的文件名
a.setAttribute("download", fileName);
document.body.append(a);
a.click();
document.body.removeChild(a);
}