使用 POST 请求实现文件的下载

发布时间 2024-01-09 19:58:19作者: 被咯苏州

以下是具体的代码实现:

const handleExportModal = async () => {
  const response = await getExportApi({
    a: xxxxxxx,
    b: xxxxxx,
  });
  const url = window.URL.createObjectURL(response.data);
  const link = document.createElement("a");
  link.href = url;
  link.setAttribute("download", `我是文件名_${new Date().getTime()}.xlsx`); // 文件名
  document.body.appendChild(link);
  link.click();
  link.remove();
  window.URL.revokeObjectURL(url);
};