乐趣区

关于前端:下载xslx二进制文件

下载 xslx 二进制文件

申请头必须 config.headers[“Content-Type”] = “application/json”;
设置 responseType 为 blob 或 arraybuffer

// 下载文件
export const downloadFile = ({obj, name = "", suffix ="xlsx"}) => {const url = window.URL.createObjectURL(new Blob([obj]));
  const link = document.createElement("a");
  link.style.display = "none";
  link.href = url;
  const fileName = new Date() + "-" + name + "." + suffix;
  link.setAttribute("download", fileName);
  document.body.appendChild(link);
  link.click();
  document.body.removeChild(link);
};
this.$api["EXPORT_LOGLIST"]({
        ...data,
        includes: ["index", "@timestamp", "message", ...this.selectedField],
        excludes: [],}).then((res) => {downloadFile({ obj: res});
      });
// 导出日志
  EXPORT_LOGLIST(data) {
    return request({
      url: "/search/conditionSearch/export",
      responseType: "blob",
      method: "post",
      data,
    });
  },
退出移动版