• 下载文件流


    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;
            }
          );
        },
    

      下载这种文件流的方式

  • 相关阅读:
    CCNA 6.9
    CCNA 6.5
    Google search
    CCNA 4.14 TP Correction
    CCNA 6.3
    CCNA 6.6
    有关 英语学习的一些网站
    法语学习笔记
    垃圾邮件分类(Scala 版本)
    SQL 面试经典问题 行列互相转化
  • 原文地址:https://www.cnblogs.com/js-liqian/p/11797302.html
Copyright © 2020-2023  润新知