示例只是教大家開始怎么做,路還是得大家自己走。采用 fetch 請求接口。僅僅是個示例,可以用 ajax、axios 等請求,這里只是教大家怎么請求blob文件。
function get() {
const data = JSON.stringify({
fileName: "八月發(fā)票.pdf",
});
fetch("你的接口", {
headers: {
"Content-Type": "application/json",
Authorization: "bearer ",
},
responseType: "blob",
params: data,
})
.then((res) => res.blob())
.then((res) => {
let file = new Blob([res], { type: "application/pdf" });
const changeUrl = URL.createObjectURL(file);
window.open(changeUrl, "__self");
})
.catch((err) => {
console.table(err);
});
}
get();