Vue 下載導出excel文件


axios({ 
   method: 'post', // get 或者是post請求
    url: '/api/street/jobRecord/export', // 請求地址
    data: params, // 請求參數
    headers: this.sessionKeys.sessionKey,
    responseType: 'blob' // 表明返回服務器返回的數據類型
}).then((res) => { // 處理返回的文件流
       const content = res
       const blob = new Blob([content], { type:'application/vnd.ms- 
       excel' })
       const fileName = this.$t('analysis.detailedStatement') + '.xls'
       if ('download' in document.createElement('a')) { // 非IE下載
           const elink = document.createElement('a')
           elink.download = fileName
           elink.style.display = 'none'
           elink.href = URL.createObjectURL(blob)
           elink.setAttribute('download', 
              this.$t('analysis.detailedStatement') + '.xls')
           document.body.appendChild(elink)
           elink.click()
           URL.revokeObjectURL(elink.href) // 釋放URL 對象
           document.body.removeChild(elink)
         } else { // IE10+下載
              navigator.msSaveBlob(blob, fileName)
         }
  })

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM