vue 文件导出

<div class="upload-button" @click="handleExportList()">批量导出</div>

//批量导出
    handleExportList() {
      const params = {
        areaId: this.staffLsitForm.area_id,
        isSalesman: this.staffLsitForm.is_salesman,
        mobile: this.staffLsitForm.mobile,
        name: this.staffLsitForm.name,
        shopId: this.staffLsitForm.shop_id,
        staffStatus: this.staffLsitForm.staff_status,
      }
      const token = getCookie(`PHPSESSID`) || '';
      var xhr = new XMLHttpRequest();
      //GET请求,请求路径url,async(是否异步)
      xhr.open('GET', `${getJavaUserbase()}/manage/shopStaff/batchExport?${paramsStr(params)}`, true);
      //设置请求头参数的方式,如果没有可忽略此行代码
      xhr.setRequestHeader("phpsessid", token);
      //设置响应类型为 blob
      xhr.responseType = "blob";
      //关键部分
      xhr.onload = function (e) {
        //如果请求执行成功
        if (this.status == 200) {
          var blob = this.response;
          var reader = new FileReader();
          reader.readAsDataURL(blob)
          reader.onload = function (e) {
            var a = document.createElement("a");
            a.download = '员工导出表格.xlsx';
            a.href = e.target.result;
            document.getElementsByTagName('body')[0].append(a); // 修复firefox中无法触发click
            a.click();
            a.remove();
          };
        }
      };
      //发送请求
      xhr.send();
      // 关闭弹窗
      this.exportBox = false;
    },

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值