移动端+微信小程序实现,手机端滑动分页代码思路

<scroll-view class="scroll-container" upper-threshold="{{sortPanelDist}}"  scroll-y="true" style="height:{{scrollHeight}}px;" bindscrolltolower="bindDownLoad">

<!-- 上面的scrollHeight参数必须要的,不然没法进行下一步,我这里为了兼容手机屏幕,使用的获取系统自适应高度 -->

<view class="con12"> 
  <block wx:for="{{homeList}}" wx:for-item="homeList" wx:for-index="index"> 
  <navigator url="../home_detail/home_detail?home_id={{homeList.s_id}}">
    <view class="index1-list">
       <image src="{{homeList.pic_url}}" class="indeximg">
       <span class="money">¥{{homeList.price}}</span>
       </image>
       <span class="cunhome-title">西厢房 · {{homeList.vil_name}}--{{homeList.s_title}}</span>
       <view class="describe">
         {{homeList.s_desc}}
        </view>
     </view>
  </navigator>
    </block>
 </view>
<!-- 上面是循环的数据 -->

</scroll-view>



var page = 1;
// 获取数据的方法,具体怎么获取列表数据大家自行发挥
var GetList = function (that) {
 wx.request({
    url: 'https://m.xxiangfang.com/index.php/Home/Xiaoxxf/home_service',  //民宿预订
    data: {
      page: page
    },
    header: {
      'Content-Type': 'application/json'
    },
    method: 'GET',
    success: function (res) {
      that.setData({
        homeList: res.data
      })
      page++;
    },
    fail: function (res) { },
    complete: function (res) { },
  })
}


Page({
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    //缓冲提醒
    wx.showToast({
      title: '加载中',
      icon: 'loading',
      duration: 400
    })
    //获取系统的参数,scrollHeight数值,微信必须要设置style:height才能监听滚动事件
    wx.getSystemInfo({
      success: function (res) {
        console.info(res.windowHeight)
        that.setData({
          scrollHeight: res.windowHeight
        })
      }
    });
  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    GetList(that);     //页面初次展示调用第一次数据,比如说5条记录
  },
  bindDownLoad: function () {
    //   该方法绑定了页面滑动到底部的事件,下拉一次请求一次数据
    wx.showToast({
      title: '加载中',
      icon: 'loading',
      duration: 400
    })
    var that = this;
    GetList(that);        //页面拉一次,加载一次
  },


})

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值