导出功能(文件流)

写在methods方法:

// 导出收支明细  文件命名加上当前日期
    exportMyWallet() {
      const power = {
        startTime: this.payDate ? this.payDate[0] : '',
        endTime: this.payDate ? this.payDate[1] : '',
        orderBy: this.orderBy,
        orderType: this.orderType,
        username: this.titleForm.userName,
        phoneNumber: this.titleForm.phoneNumber,
        businessType: this.titleForm.transType,
        channel: this.titleForm.transChannels
      }
      Object.keys(power).forEach(key => {
        if (power[key] === null || power[key] === '') {
          delete power[key]
        }
      })
      let d = new Date()
      var dstr = d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate()
    // exportWallet是api接口方法
      exportWallet(power).then(res => {
        const link = document.createElement('a')
        const blob = new Blob([res.data], { type: 'application/vnd.ms-excel' })
        link.style.display = 'none'
        link.href = URL.createObjectURL(blob)
        let name = '收支明细' + '(' + dstr + ')' + '.xls'
        link.setAttribute('download', name)
        document.body.appendChild(link)
        link.click()
        document.body.removeChild(link)
      })
    }

 

上一篇:排兵布阵问题


下一篇:浏览题