zoukankan      html  css  js  c++  java
  • 下载文件流

    Vue.prototype.$xlsx_get = function (url, data, fun, err) {
      axios({
          method: 'get',
          url: url,
          responseType: "blob",
          headers: {
            'Authorization': userName ? userName.token_type + userName.access_token : "Basic emh4eTp6aHh5"
          },
          params: data,
        }).then(function (res) {
          if (fun) {
            fun(res)
          }
        })
        .catch(function (error) {
          if (err) {
            err(error)
          }
        });
    }
    

      

        // 下载
        downLoadClick(row) {
          console.log(row);
          this.$xlsx_get(
            `/dcenter/backup/download/${row.id}`,
            {},
            res => {
             const blob = new Blob([res]);
                  console.log(blob);
                  const elink = document.createElement("a");
                  const fileName = '名字.xlsx';
                  elink.download = fileName;
                  elink.style.display = "none";
                  elink.href = URL.createObjectURL(blob);
                  document.body.appendChild(elink);
                  elink.click();
                  URL.revokeObjectURL(elink.href); // 释放URL 对象
                  document.body.removeChild(elink);
                  this.isDefault = false
                  this.$message.success("导出成功");
              console.log(res);
            },
            err => {
              this.$message.error(err.msg)
              throw err;
            }
          );
        },
    

      下载这种文件流的方式

  • 相关阅读:
    AxMIMS系统开发环境搭建
    基于霍夫变换的点云分割方法
    微惯性导航系统
    “导航技术”学习笔记
    Kalman滤波学习
    Cell complex单元复形
    矩阵与欧拉角的转换
    CGAL4.10 / CGAL4.13编译
    [OpenCV]代码整理
    KinectFusion测试
  • 原文地址:https://www.cnblogs.com/js-liqian/p/11797302.html
Copyright © 2011-2022 走看看