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

InfiniteScroll 重复触发 loadMore 方法 #4355

Closed
1 task done
zcrkey opened this issue Nov 10, 2021 · 8 comments
Closed
1 task done

InfiniteScroll 重复触发 loadMore 方法 #4355

zcrkey opened this issue Nov 10, 2021 · 8 comments

Comments

@zcrkey
Copy link

zcrkey commented Nov 10, 2021

Version of antd-mobile

5.0.0-beta.24

Operating system and its version

No response

Browser and its version

No response

Sandbox to reproduce

https://codesandbox.io/s/nervous-gwen-6yk7u?file=/src/list.js

What happened?

1、加载多页数据之后,点击搜索按钮,就会频繁触发 loadMore 方法
2、加载多页数据之后,点击下拉框1,然后再点击取消按钮,也会频繁触发 loadMore 方法

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@awmleer
Copy link
Member

awmleer commented Nov 10, 2021

你在 onSearch 里把数据重置了,导致内容区域的高度不够,自然就会触发 InfiniteScroll 的 loadMore 了,这应该是预期的行为啊

可以具体描述一下你期望的行为是什么样的么?

@zcrkey
Copy link
Author

zcrkey commented Nov 10, 2021

onSearch 方法把数据重置了,导致内容区域的高度不够,会触发 InfiniteScroll 的 loadMore 方法
在 loadMore 方法中再添加了数据,这个时候内容区域的高度是够的了,还是会再次触发 InfiniteScroll 的 loadMore 方法

我的操作如下
image
image

@xiaoliu1990
Copy link

看了下,应该是滚动的问题,第一次加载几页内容,滚动几屏后,在点击搜索或者下拉的时候,为了重新定义到之前滚动的地方,就要重复请求。如果加载几页,在滚动到首屏,点击下拉或者搜索就不会重复触发了。可以考虑每次查询数据返回之前scroll重置为0。

@zcrkey
Copy link
Author

zcrkey commented Nov 10, 2021

每次查询数据返回之前将scroll重置为0,确实是能解决该重复调用问题!
不过这样操作是否有点繁琐呢?有没有更加好的实现呢

@awmleer
Copy link
Member

awmleer commented Nov 10, 2021

在你发的这 demo 里,将 scroll 重置为 0 应该是最优也是最合理的方案了,因为你如果不把 scroll 重置掉,用户点了刷新按钮之后,列表还处在一个中间的位置,这也是不合逻辑的,而且已经不是 InfiniteScroll 的问题了

至于别的更优雅的解法,我来写个 demo 挂到文档上吧

@awmleer
Copy link
Member

awmleer commented Nov 10, 2021

可以参考这个 demo: 3db3a8a

@zcrkey
Copy link
Author

zcrkey commented Nov 10, 2021

好的,我已经明白了,谢谢!

@ycshill
Copy link

ycshill commented Aug 9, 2024

中再添加了数据,这个时候内容

为什么内容区域不够就要触发啊,好不合理

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

4 participants