Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

table列表当后端total返回的数据类型为string且值’0‘时,类型报错且会重复请求 #7854

Open
ajlsuperman opened this issue Feb 25, 2025 · 1 comment

Comments

@ajlsuperman
Copy link

前端-源码代码位置:@/components/Table/src/hooks/useDataSources.ts
源码:
function fetch(){
......

  const resultTotal: number = isArrayResult ? 0 : get(res, totalField); 

  // 假如数据变少,导致总页数变少并小于当前选中页码,通过getPaginationRef获取到的页码是不正确的,需获取正确的页码再次执行
  if (resultTotal) {
    const currentTotalPage = Math.ceil(Number(resultTotal) / pageSize);
    if (current > currentTotalPage) {
      setPagination({
        current: currentTotalPage,
      });
      return await fetch(opt);
    }
  }

......
}
// 建议这里加上Number()做容错处理。
const resultTotal: number = isArrayResult ? 0 : Number(get(res, totalField));
当后端返回数据为字符串时,且total=‘0’时,会导致if (resultTotal) {...}执行,那就会发现重复请求。

@zhangdaiscott
Copy link
Member

版本号?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants