下载:
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); }) 标签:const,预览,url,前端,href,link,blob,文档 From: https://www.cnblogs.com/evenbest/p/18034666