接口返回二进制文件的下载。

export function userPrizeListDownload(
  params: Partial<UserPrizeList>,
) {
  return requestLotteryApi(`/xxx/download`, {
    params,
    responseType: 'arrayBuffer',  //这部分指定了响应的类型为arrayBuffer,表示希望以二进制数据的形式接收响应。
  });
}
 
 
复制代码
const prizeListDownloadData = await userPrizeListDownload(
        newCurrentParams,
      );
    
    //
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',

const blob = new Blob([prizeListDownloadData], { type: 'application/csv', }); const link = document.createElement('a'); // 下载后的文件名 link.download = 'xxx.xlsx'; link.href = URL.createObjectURL(blob); document.body.appendChild(link); link.click(); //释放URL对象 URL.revokeObjectURL(link.href); document.body.removeChild(link); message.success('成功');
复制代码

 

 

posted @   炽橙子  阅读(38)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
历史上的今天:
2022-06-24 css背景透明文字不透明
2022-06-24 addEventListener() 方法,事件监听
点击右上角即可分享
微信分享提示