前端文件流导出

1、前端代码

javascript 复制代码
​
/** 导出 */
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、后端返回数据:

相关推荐
生戎马 平安京策17 分钟前
只学一点点:我的技术学习策略
前端·javascript·react.js
大鹏说大话30 分钟前
HTML5 地理定位 Geolocation:获取用户位置的“红线”与最佳实践
前端·html·html5
Csvn1 小时前
content-visibility: auto —— 让浏览器跳过离屏渲染的性能黑科技
前端
小鹰信息技术服务部1 小时前
Edge安装包MicrosoftEdgeSetup.exe无法运行,点击没反应
前端·edge
webkubor2 小时前
一次前端生产白屏复盘:旧 HTML、Hash 资源和 MIME type text/html
前端·前端工程化
咩咩啃树皮2 小时前
第63篇【终极整合巨作】从零手写原生中后台管理系统|整合62篇全部前端知识点|从头到尾完整架构+全功能逻辑
前端·架构
Highcharts3 小时前
用Highcharts如何动态向一个序列添加点-示列讲解
前端
weixin_431600443 小时前
做 Agent 会用到的 Node API(4):取消与 AbortController
前端·学习·ai·agent·ai编程
JiaLin_Denny3 小时前
Vue3中ref和reactive用法与双向数据绑定
前端·javascript·vue.js
用户2181697049303 小时前
Flutter(十)Container Center Align
前端