文档管理中心
我的

如何实现List/Swiper/Grid嵌套滚动的下拉刷新和上拉加载更多

开发者可通过Refresh组件嵌套List实现下拉刷新。刷新逻辑在onRefreshing回调方法中执行。上拉加载更多给List添加onReachEnd事件回调,列表滑动到底部时触发。示例代码如下:

收起
自动换行
深色代码主题
复制
  1. build() {
  2. Column() {
  3. // Search box at the top
  4. this.searchBarBuilder()
  5. // Pull down refresh component
  6. Refresh({ refreshing: $$this.isRefreshing }) {
  7. // List component as long list layout
  8. List({ space: 10 }) {
  9. // ListItem Customize the Swiper carousel module
  10. ListItem() {
  11. this.bannerBuilder()
  12. }
  13. // ListItem Custom Grid Quick Access Module
  14. ListItem() {
  15. this.quickBuilder()
  16. }
  17. // ListItem Custom Column Flash Sale Module
  18. ListItem() {
  19. this.flashBuilder()
  20. }
  21. // ListItemGroup Product Classification List
  22. this.productsBuilder()
  23. // 最后ListItem Customize bottom loading for more
  24. ListItem() {
  25. this.footerLoadingBuilder()
  26. }.height(50).width('100%').backgroundColor(0xeeeeee)
  27. }
  28. .sticky(StickyStyle.Header)
  29. .height('100%')
  30. // List component hits bottom to simulate network requests
  31. .onReachEnd(() => {
  32. // Load more data logic
  33. })
  34. }
  35. // Pull down refresh simulation network request
  36. .onRefreshing(() => {
  37. // Data refresh logic
  38. })
  39. .layoutWeight(1)
  40. .width('100%')
  41. }
  42. }