vue+axios 下载后端返回的文件流


axios({
      method: 'get',
      url: url,
      params: payload,
      responseType: 'blob',    // 必须加上
      headers: {
        'Content-Type': 'multipart/x-www-form-urlencoded'
      }
 })

 

axios(url).then((res)=>{
          let blob = new Blob([res.data])
          let downloadElement = document.createElement('a')
          let href = window.URL.createObjectURL(blob)
          downloadElement.href = href
          downloadElement.download = '数据导出.xls'
          document.body.appendChild(downloadElement)
          downloadElement.click()
          document.body.removeChild(downloadElement)
          window.URL.revokeObjectURL(href)
})

 


免责声明!

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



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