axios 下载文件


@GetMapping("/excel_export")
    public void excelExportInfo(HttpServletResponse response)  {

        try {
            response.setContentType("application/vnd.ms-excel");
            response.setContentType("application/x-download");
            response.setContentType("multipart/form-data");
            response.setCharacterEncoding("utf-8");
            response.setHeader("Cache-Control", "no-cache");
            response.setHeader("Content-disposition", "attachment;filename=camera.xlsx");
            // List<模型> 的数据体,替换成自己的业务代码即可
            List videoCameraVOS = videoCameraService.findPageByKeyword(1, 10000,"").getRecords();
            EasyExcel.write(response.getOutputStream(), VideoCameraVO.class).sheet("摄像机").doWrite(videoCameraVOS);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
export function excelExport() {
  return request({
    url: '/host-machine/excel_export',
    method: 'get',
    responseType: 'blob'
  })
}

if (response.request.responseType == "blob") {
      let url = window.URL.createObjectURL(new Blob([res]))
      let a = document.createElement('a')
      a.style.display = 'none'
      a.href = url
      a.setAttribute('download','excel.xlsx')
      document.body.appendChild(a)
      a.click() //执行下载
      window.URL.revokeObjectURL(a.href) //释放url
      document.body.removeChild(a) //释放标签
    }

你可能感兴趣的:(axios 下载文件)