handleDownload() {
const url = "/pdf/user.pfh"; // 替换成实际的PDF文件路径
fetch(url, {
method: "GET",
headers: { "Content-Type": "application/pdf" },
})
.then((response) => response.blob())
.then((blob) => {
const url = window.URL.createObjectURL(new Blob([blob]));
const link = document.createElement("a");
link.href = url;
link.setAttribute("download", "xxx.pdf"); // 设置下载文件的名称
document.body.appendChild(link);
link.click();
link.parentNode.removeChild(link);
})
.catch((error) => {
console.error("Error downloading PDF file: ", error); // 处理下载失败的情况
});
},
09-13
1200
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
10-02
4498
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-14
7617
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-19