antd-pro实现下载功能

在antd-pro中实现下载功能, 前端页面可以这样写

<Button onClick={this.onDownLoadClick}> 下载</Button>
  onDownLoadClick = () => {
    const fileName = "下载文件.txt";
    const { dispatch } = this.props;
    dispatch({
      type: 'list/download',
      payload: {
        "id": 64,
      },
      callback: (response) => {
        console.log(response)
        // if (response.success) {
        const blob = new Blob([response]);
        const aLink = document.createElement('a');
        aLink.style.display = 'none';
        aLink.href = blob;
        aLink.download = fileName;
        document.body.appendChild(aLink);
        aLink.click();
        document.body.removeChild(aLink);
        // }
      }
    });
  }

但是我下载下来的文件内容并不是后台需要的内容 ,
在这里插入图片描述
我感觉应该是后台代码的问题
后来后台人员直接把下载的请求改成get方式,
前端只需要

window.open('/url/download?id=1')

就可以实现下载 , 说实话 不知道后台干了啥

发布了47 篇原创文章 · 获赞 42 · 访问量 14万+

猜你喜欢

转载自blog.csdn.net/zm_miner/article/details/95209432
今日推荐