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)
})

 

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

上一篇:CCNA - Part8 - Cisco IOS Switch, Router 基础配置


下一篇:制作连接ESP8266 WiFi模块WiFi的Android客户端APP控制单片机外围LED灯亮灭