前端 使用 js-file-download 下载后端返回的Excel文件


  • 安装

    npm install js-file-download --save
    • 使用
        •   import fileDownload from 'js-file-download'
            let _that=this
                      _that.$axios.get(_that.$api.etmservice+"/export/excel/datamonitor",

                          {
                              responseType: 'blob',
                              headers: {
                                  'Content-Type': 'application/octet-stream'
                              }
                          })
                          .then(function(res){
                                  fileDownload(res.data,'safa.xlsx')
                          })
           

会出现打开文件损坏问题

解决    

  responseType: 'blob',

headers:{
  'Content-Type': 'application/json; application/octet-stream'
},

这俩都指定下就好了


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM