vue导出功能


        下载导出结果

// 下载导出结果
const downLoadClick = async () => {
  try {
    const response = await axios({
      url: `${getBaseUrl()}/gpt/admin/messageExport/download`,
      method: "GET",
      responseType: "blob", // 指定响应类型为 blob
      headers: {
        "iam-auth": localStorage.getItem(`access_token`) || "",
        token: localStorage.getItem(`admin-token`) || "",
      },
    });
    console.log(response, "response");
    const url = window.URL.createObjectURL(new Blob([response.data]));
    const link = document.createElement("a");
    link.href = url;
    link.download = `对话消息${
      startTime.value ? startTime.value?.format("YYYY-MM-DD HH:mm:ss") : ""
    }-${
      endTime.value ? endTime.value?.format("YYYY-MM-DD HH:mm:ss") : ""
    }.xlsx`;
    link.click();
    window.URL.revokeObjectURL(url);
  } catch (error) {
    console.error("导出文件时出现错误:", error);
  }
};

你可能感兴趣的:(vue.js,javascript,前端)