vue 導(dǎo)出xls

//導(dǎo)出記錄
      let _this = this
      const padata = {
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        startTime: this.startTime,
        endTime: this.endTime,
        keywords: this.nameOrPhoneNumber,
        appId: localStorage.getItem('appId')
      }
      let token = localStorage.getItem('token')
      axios
        .post('/api/merchant/outputVisitorLog', qs.stringify(padata), {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded', //請(qǐng)求的數(shù)據(jù)類(lèi)型為form data格式
            'X-Access-Token': token
          },
          responseType: 'blob' //設(shè)置響應(yīng)的數(shù)據(jù)類(lèi)型為一個(gè)包含二進(jìn)制數(shù)據(jù)的 Blob 對(duì)象,必須設(shè)置?。。?        })
        .then(response => {
          if (response.data.code) {
            _this.$message.error(response.msg)
          } else {
            const blob = new Blob([response.data], { type: 'application/octet-stream;charset=utf-8' })
            const fileName = '訪客預(yù)約記錄.xls'
            const linkNode = document.createElement('a')
            linkNode.download = fileName //a標(biāo)簽的download屬性規(guī)定下載文件的名稱
            linkNode.style.display = 'none'
            linkNode.href = URL.createObjectURL(blob) //生成一個(gè)Blob URL
            document.body.appendChild(linkNode)
            linkNode.click() //模擬在按鈕上的一次鼠標(biāo)單擊
            URL.revokeObjectURL(linkNode.href) // 釋放URL 對(duì)象
            document.body.removeChild(linkNode)
          }
        })
        .catch(error => {
          console.log(error)
        })
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容