关于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: "网络连接谬误" });
 });

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理