vue 后台獲取文件流導出excel文件


let params = {
        compStartTm: Date.parse(this.searchForm.compStartTm) / 1000,
        compEndTm: Date.parse(this.searchForm.compEndTm) / 1000 + 86400,
        collectWay: this.searchForm.collectWay,
      };
      this.loading = true;
      var _this = this;
      this.$httpExt().post("/xxxx/xxxxxx", params, { responseType: 'arraybuffer' }).then(res => {
        if (res) {
          _this.loading = false;
          const aLink = document.createElement("a");
          let blob = new Blob([res.data], {type: "application/vnd.ms-excel"})
          aLink.href = URL.createObjectURL(blob)
          aLink.setAttribute('download', '哈哈哈哈' + '.xlsx') // 設置下載文件名稱
          aLink.click()
          this.$refs.loadElement.appendChild(aLink)
        }
      },res => {
        _this.$message.error(res.msg);
        _this.loading = false;
      });

 參考地址:https://segmentfault.com/a/1190000020540788 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM