下载文件
function download(url) {
const link = document.createElement("a");
link.download = "file name";
link.href = url;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
静态资源服务器设置响应头也能触发浏览器下载。
Content-Disposition: attachment; filename="filename.jpg"