前端 使用 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'
},

这俩都指定下就好了

posted @ 2020-08-05 09:17  孙同学你好  阅读(3422)  评论(0编辑  收藏  举报