1.直接打开url地址,地址可以是绝对路径或者接口拼接的地址
location.href = url
2.接口返回文档流
axios({ method: data.method, url: `${data.url}${data.params ? "?" + data.params : ""}`, responseType: "blob", data: data.data }) .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 = res.headers['content-disposition'] //下载后文件名 link.download = data.fileName; //下载的文件名 document.body.appendChild(link); link.click(); document.body.removeChild(link); }) .catch(error => { this.$Notice.error({ title: "错误", desc: "网络连接错误" }); // console.log(error); });
标签:文件,url,res,js,link,blob,error,data,下载 From: https://www.cnblogs.com/lb0121/p/16798574.html