微信小程序上拉加载下拉刷新值scroll-view

本文详细介绍了如何使用小程序scroll-view组件实现上拉刷新和下拉加载更多功能。通过设置组件属性,如高度、滚动方向及事件绑定,配合JS代码动态加载数据,实现流畅的用户体验。

Hello,大家好!上次更新的也上拉刷新,下拉加载的效果,只不过今天用的是小程序scroll-view的组件。首先我们了解一下此组件的属性。


1、首先,要使用scroll-view组件,纵向滚动,我们要给scroll-view设置一个固定的高度。否则无法触发我们绑定的时间,这个是必须的。

2、我们先看一下代码吧,css代码我就不贴出来了,大家自己动手谢谢吧!

   <scroll-view class="scroll_container" scroll-y="true" bindscrolltoupper="refresh"          bindscrolltolower="loadMore">

       <navigator class='box' hover-class='none' wx:for="{{list}}" data-id="{{item.id}}" >
                <view class='box_left'><image src='{{item.itemIconUrl}}'></image></view>
      <view class='box_right'>
              <view class='over1 sname'>【{{item.sname}}】{{item.sdescription}}</view>
              <view class='price'>
                  <view class='promotePrice'>¥{{item.promotePrice}}</view>
                 <view class='itemprice'>¥{{item.price}}<view class='line'></view></view>
              </view>
    <view class='makemoney'>
               <view class='make'>¥{{item.promotePrice*0.05}}</view>
               <view class='promote'>保险</view>
    </view>
</view>
      </navigator>
</scroll-view>

JS代码:

 onLoad: function(options) {
var that = this;
var data = { doctorUserIdKey: '001' }
http.httpGet('doctor/getDoctorUserId', data, function (res) {
success: {
var doctorUserId = res.data.doctorUserId;
var data = { doctorUserId: doctorUserId, categoryId: 0, hot: 0}
http.httpGet('接口', data, function (res) {
console.log(res);
success:{
that.setData({
list:res.data.list,
page: res.data.page
})
}
})
}
})
},
refresh:function(e){
},
loadMore:function(e){
var that = this;
var page = that.data.page;
var page_size = page.page_size;
var all_count = page.all_count;
console.log(all_count);
console.log(page_size)
if(page_size<=all_count){

如果数据的总数大于每页的数据量,那么数据量每次+10,

弹窗显示数据正在加载,模拟原生加载。

var page_size = page_size+10;
var data = { doctorUserIdKey: '001' }
http.httpGet('接口', data, function (res) {
success: {
wx.showToast({
title: '数据正在加载',
icon: 'loading',
duration: 1000
})
var doctorUserId = res.data.doctorUserId;
var data = {参数}
http.httpGet('接口', data, function (res) {
console.log(res);
success: {
that.setData({
list: res.data.list,
page: res.data.page
})
}
})
}
})
} else if (page_size>all_count){

如果数据的总数小于每页的数据量,

弹窗显示数据没有更多,模拟原生加载。

wx.showToast({
title: '没有更多数据了',
icon: 'none',
duration:1000
})
}
},

共享知识,共同进步


转载于:https://juejin.im/post/5be3cf9be51d454b8029862e

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值