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

38次阅读

共计 730 个字符,预计需要花费 2 分钟才能阅读完成。

下载 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