前端下载文件(GET、POST方法)

GET

location.href = '/path/to/download/url'

POST

本例使用axios

axios.post('/path/to/download/url', this.searchParams, {
  responseType: 'blob'
}).then(res => {
  let blob = res.data
  let reader = new FileReader()
  reader.readAsDataURL(blob)
  reader.onload = (e) => {
    let a = document.createElement('a')
    a.download = `表格名称.xlsx`
    a.href = e.target.result
    document.body.appendChild(a)
    a.click()
    document.body.removeChild(a)
  }
}).catch(err => {
  console.log(err.message)
})
    原文作者:arashethis
    原文地址: https://blog.csdn.net/u010986031/article/details/79474393
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞