js图片不打开直接下载(文件下载)

fetch(放要下载的url).then(async res => await res.blob()).then((blob) => {

   const a = document.createElement('a');

   a.style.display = 'none';

   a.href = URL.createObjectURL(blob);

   a.download = 放要下载的名字;

   document.body.appendChild(a);

   a.click();

   document.body.removeChild(a);

})

posted @ 2022-02-22 16:57  彳小闲鱼  阅读(219)  评论(0编辑  收藏  举报