乐趣区

关于vue.js:vue后台传文件流blob对象前台点击下载

 this.$axios

 .get("/wx/villageargot/export", {

 params: {subDistrictId: this.query.streetId},

 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);
     let num = "";
     for (let i = 0; i < 10; i++) {num += Math.ceil(Math.random() * 10);
     }
     link.setAttribute("download", "用户_" + num + ".xls");
     document.body.appendChild(link);
     link.click();
     // 间接删除了 a 标签 无需通过 window.URL.revokeObjectURL(link.href) 开释内存
     document.body.removeChild(link);
     NProgress.done();})
 .catch(error => {this.$Notice.error({ title: "谬误", desc: "网络连接谬误"});
 });
退出移动版