导出EXCEL表格

 openOutDia () {
      let url = this.api + '接口地址'
      let params = {   //传参数
        page_no: this.page,
        page_size: this.pageSize,
        shop_id: this.user.shopid,
        start_time: this.time === '' ? this.defaultStart : this.time[0],
        end_time: this.time === '' ? this.defaultEnd : this.time[1],
        is_export: this.export
      }
      // responseType返回的文件流
      this.$ajax.get(url, { params, responseType: 'blob' }).then((response) => { // 这里是声明期望返回的数据类型,为blob
        const url = window.URL.createObjectURL(new Blob([response.data])) // 这里调用window的URL方法
        const link = document.createElement('a') // 对象中创建一个对象,要与appendChild() 或 insertBefore()方法(在节点的子节点列表任意位置插入新的节点)联合使用
        link.style.display = 'none'  // 隐藏
        link.href = url
        link.setAttribute('download', '导出配方货品(成本与请货)记录.xls') //下载文档名称及后缀
        document.body.appendChild(link) // 在节点的子节点列表末添加新的子节点
        link.click() // 点击
        document.body.removeChild(link) // 下载完成移除元素
        window.URL.revokeObjectURL(url) // 释放掉blob对象
      }).catch(err => {
        this.tableData = []
        this.loading = false
        console.log(err)
      }) 
    },

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值