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