解析后端传来的excel

365 阅读1分钟

请求数据, 需要指定 responseType: "blob"

axios({
    url: "",
    responseType: "blob"
})

下载excel

export function downloadExcel(data, name) {
  let blobObj = new Blob([data], {
    type: "application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
  });
  let a = document.createElement("a");
  a.href = URL.createObjectURL(blobObj);
  a.download = name;
  a.click();
}