zoukankan      html  css  js  c++  java
  • vue下载excel文件,后台传过来的是文件流解决办法

     

     downErrorExcel() {
          getdownAjax(
            url +
              upmsUrl +
              "/admin/teacher/download/excel/error/" +
              this.uploadError_downId,
            { responseType: "blob" }
          ).then(res => {
            let blob = new Blob([res], { type: "application/vnd.ms-excel" }); // res就是接口返回的文件流了
            let objectUrl = URL.createObjectURL(blob);
            window.location.href = objectUrl;
          });
        },
     
     
     ========================================方二
    //导出excel表
    Vue.prototype.exportExcel = (Url, FileName) => {
      getdownAjax(Url, {
        responseType: "blob"
      }).then(res => {
        // console.log("res", res);
        if (res) {
          let blob = new Blob([res.data], {
            type: "application/vnd.ms-excel;charset=utf-8"
          }); // res就是接口返回的文件流了
          let objectUrl = URL.createObjectURL(blob);
          // console.log(objectUrl);
          // const fileName = FileName;
          const elink = document.createElement("a");
          elink.download = FileName; //下载文件名称,
          elink.style.display = "none";
          elink.href = objectUrl;
          document.body.appendChild(elink);
          elink.click();
          URL.revokeObjectURL(elink.href); // 释放URL 对象
          document.body.removeChild(elink);
        }
      });
    }

     tablebtn_exportAll() {
          this.exportExcel(
            url + upmsUrl + "/admin/student/export",
            "学员列表.xlsx"
          );
        },
  • 相关阅读:
    JFinal 数据库“手动”事务(提交、回滚)
    redis有序集合性能 列表、集合、有序集合
    比特币的原理
    word2vec原理总结
    xgboost 算法总结
    GBDT学习笔记
    LR 算法总结--斯坦福大学机器学习公开课学习笔记
    sklearn的基本使用
    批量梯度下降(BGD)、随机梯度下降(SGD)以及小批量梯度下降(MBGD)的理解
    Logistic回归计算过程的推导
  • 原文地址:https://www.cnblogs.com/yixiaoyang-/p/13042540.html
Copyright © 2011-2022 走看看