/**
* 下载文件
*/
const downloadFile = (url) =>{
const a = document.createElement('a');
a.href = url+ '?response-content-type=application/octet-stream';;
document.body.appendChild(a);
const parts = url.split('/');
const fileName = parts[parts.length - 1];
a.download = fileName;
// 模拟点击链接来触发下载
a.click();
}
'?response-content-type=application/octet-stream'; 一定要加
本文介绍了一个使用JavaScript编写的函数,通过创建`a`标签模拟点击,实现从指定URL下载文件,特别强调了添加`?response-content-type=application/octet-stream`的重要性。
7029

被折叠的 条评论
为什么被折叠?



