ajax|axios通过get方式下载Excel

vue+element环境下的写法,其它框架也基本一样
【ajax|axios通过get方式下载Excel】主要是将后台返回的数据处理之后下载为.xlsx的文件,再模拟点击下载

axios({ method: "get", url: "url****", responseType: "blob",// 重点 headers: {***}, params: params, }) .then((res) => { let url = window.URL.createObjectURL(new Blob([res.data])); let link = document.createElement("a"); link.style.display = "none"; link.href = https://www.it610.com/article/url; link.setAttribute("download", this.$route.meta.title + ".xlsx"); document.body.appendChild(link); link.click(); }) .catch(() => { this.$message.error("网络错误!"); });


    推荐阅读