本文共 766 字,大约阅读时间需要 2 分钟。
后台接口返回的数据
代码部分:
this.axios({ method: "get", headers: { "content-type": "application/json", // 默认值 Authorization: "Bearer " + sessionStorage.getItem("access_token"), }, url: 'your_URL', params: {'name':'Jack'}, responseType: "blob", }) .then(function (res) { let blob = new Blob([res.data]); // { type: "application/vnd.ms-excel" } let url = window.URL.createObjectURL(blob); // 创建一个临时的url指向blob对象 // 创建url之后可以模拟对此文件对象的一系列操作,例如:预览、下载 let a = document.createElement("a"); a.href = url; a.download = "表格.xlsx"; a.click(); // 释放这个临时的对象url window.URL.revokeObjectURL(url); }) .catch(function (res) { console.log("error", res); });
转载地址:http://nuwnz.baihongyu.com/