下载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,
    });
  },

一个大秤砣
0 声望0 粉丝