微信小程序-下拉刷新,上拉加载更多

又是一天,继续小程序之旅,这一次把项目优化了一下布局,不至于那么丑了,然后实现了上拉加载更多,下拉刷新,需要滚轮操作才可以,鼠标多拽好像不灵活。

效果图

这里写图片描述

简单的说一下实现我的实现思路:

布局
<scroll-view  style="height: {{windowHeight}}px; width: {{windowWidth}}px;" scroll-y="true" bindscrolltoupper="pullDownRefresh" bindscrolltolower="pullUpLoad" >
  <navigator url="../newDetail/newDetail?id={{item.menuId}}" redirect="false" wx:for="{{caiItems}}" hover-class="navigator-hover">
      <view class="test_item">
      <image class="item_img" src="{{item.thumbnail}}" mode="scaleToFill"></image>
      <text class="item_content">{{item.name}}</text>
      </view>
 </navigator>
</scroll-view>

核心就是:

```
style="height: {{windowHeight}}px; width: {{windowWidth}}px;" scroll-y="true" bindscrolltoupper="pullDownRefresh" bindscrolltolower="pullUpLoad"
JS中实现相对应的方法
  onShow: function( e ) {
    wx.getSystemInfo( {
      success: ( res ) => {
        this.setData( {
          windowHeight: res.windowHeight,
          windowWidth: res.windowWidth
        })
      }
    })
  },
  pullDownRefresh: function( e ) {
    console.log( "下拉刷新...." )
    this.onLoad()
  },

  pullUpLoad: function( e ) {
    this.setData( {
      page: this.data.page + 1
    })

    console.log( "上拉拉加载更多...." + this.data.page )

    this.getDataFromServer( this.data.page )
  },

}

就可以实现了,具体实现可以参考代码

GitHub地址


关注博主是一种态度,评论博主是一种欣赏!!

欢迎关注我的微博:
http://weibo.com/u/5345060833

关注微信公众号:YangZheShare
(欢迎关注,最新最实用的技术干货分享)
微信开发平台

  • 4
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值