通过接口下载excel文件及其相关知识点

this.$http({
  url: "XXX/download",
  method: "get",
  params: XXX,
  headers: {
    "Content-Type": "application/json; application/octet-stream"
  },
  responseType: "arraybuffer"
}).then(({ data }) => {
  const blob = new Blob([data], { type: "application/vnd.ms-excel" });
  const downloadElement = document.createElement("a");
  const href = window.URL.createObjectURL(blob);
  downloadElement.href = href;
  downloadElement.download = "XXX.xls";
  document.body.appendChild(downloadElement);
  downloadElement.click();
  document.body.removeChild(downloadElement); // 下载完成移除元素
  window.URL.revokeObjectURL(href); // 释放掉blob对象
});

你可能感兴趣的:(通过接口下载excel文件及其相关知识点)