前端文件流导出

阅读 21

2024-10-29

1、前端代码

​
/** 导出 */
const handleExport = async () => {
  let config = {
    responseType: 'blob',
    headers: {
      'Content-Type': 'application/json',
    },
  };
  const res = await getTargetExport(config);
  const blob = new Blob([res]);

  const fileName = 'PK目标跟进导出列表.xls';
  const linkNode = document.createElement('a');

  linkNode.download = fileName;
  linkNode.style.display = 'none';

  linkNode.href = URL.createObjectURL(blob);
  document.body.appendChild(linkNode);

  linkNode.click();
  URL.revokeObjectURL(linkNode.href);
  document.body.removeChild(linkNode);
};

/** 导出接口 */
export const getTargetExport = config => {
  return request(`${prefixPath}/target-follows/export`, {
    method: 'GET',
    ...config,
  });
};

​

2、后端返回数据:

精彩评论(0)

0 0 举报