1. 程式人生 > 其它 >匯出功能(檔案流)

匯出功能(檔案流)

寫在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) }) }