const link = document.createElement("a");//创建一个a链接
fetch(url) //url是你的地址
.then((res) => res.blob())
.then((blob) => {
link.href = URL.createObjectURL(blob);
link.download = name; // name :下载的文件名
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
});
js使用fetch下载docx和doc文件
最新推荐文章于 2023-04-12 18:22:34 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)