0
点赞
收藏
分享

微信扫一扫

前端文件流导出

WikongGuan 2024-10-29 阅读 21
前端

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 条评论