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

  

猜你喜欢

转载自www.cnblogs.com/zhaomeizi/p/11398517.html