下载:

axios({
    url: `url`,
    method: "post",
    data: {
     参数...
    },
    responseType: "blob",
  })
.then((res)=>{
  const link = document.createElement("a");
      let blob = new Blob([res.data], { type: "application/vnd.ms-excel" });
      link.style.display = "none";
      link.href = URL.createObjectURL(blob);
      link.download = "下载文档" + ".xls"; //下载的文件名
      document.body.appendChild(link);
      link.click();
      document.body.removeChild(link);
})
预览:
axios({
    url: `url`,
    method: "post",
    data: {
     参数...
    },
    responseType: "blob",
  })
.then((res)=>{
 const blob = new Blob([response], { type: "application/pdf" });
    const href = window.URL.createObjectURL(blob);
    window.open(href);
})
 posted on 2024-02-26 16:39  久闻  阅读(109)  评论(0)    收藏  举报