Hi FE !
Ai
git
前端面试题
前端小tip
  • vite
  • webpack
npm
  • vue2
  • vue3
react
GitHub
Ai
git
前端面试题
前端小tip
  • vite
  • webpack
npm
  • vue2
  • vue3
react
GitHub
  • 下载文件

下载文件

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"
Edit this page
最近更新: 2025/6/27 02:24
Contributors: qdleader
qdleader
本站总访问量 129823次 | 本站访客数 12人