uniapp使用 scroll-view 进行触底加载列表

本文介绍了如何在uni-app应用中使用scroll-view组件进行区域滚动,并实现列表的动态加载功能。当滚动到底部时,会触发loadMore函数判断是否需要加载更多数据,通过接口获取并更新列表内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

可滚动视图区域。用于区域滚动。

具体使用可以参考 scroll-view | uni-app官网

1.template部分

<scroll-view scroll-y="true" class="scrollbox" :scroll-top="scrollTop" @scrolltolower="loadMore">
      // 这里没有数据时 我是用了一个封装的组件
      <empty-tips class="noData" v-if='list&&list.length==0' :tips-list="['暂无数据']" />
      // 这里是列表
      <view class="item" v-else>
          <view v-for="(item,index) in list"  :key="index">
      </view>
   </view>
</scroll-view>

2.script部分

    loadMore() {
        console.log('触底了')
        // 判断需不需要加载列表
        if(this.current*this.size<this.total){
          this.current++;
          this.commanderInfo(false);
        } else {
          console.log('没有最新啦')
        }
      },
    commanderInfo(isInit=true) {
        if (isInit) {this.current = 1}
        wx.showLoading();
        http.request({
          url: '这里是接口地址',
          method: 'get',
          data: {
            size: this.size,
            current: this.current,
          },
          callBack: (res) => {
            this.total = res.total
            if (this.current == 1)
              this.list= [];
            wx.hideLoading();
            this.rescord = res
            const list = res.records
            this.list= this.list.concat(list)
          }
        })
      }

3.css部分

这列需要设置高度,一开始我没有设置高度  触底没有作用

.scrollbox {
	height: calc(100vh - 600rpx);
	overflow: auto;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值