微信小程序监听页面上拉加载

js代码

  onReachBottom: function () {
    //console.log('页面上拉触底事件的处理函数');

    let pthis = this;
    let page = this.data.page;
    let newpage = page + 1;


    app.util.request({
      url: 'entry/wxapp/Fotoplace',
      data: {
        m: 'zhou_youx',
        uid: app.globalData.uid,
        page: newpage,

      },
      method: 'post',
      success: function (response) {


        if (response.data.code == 120000) {

          wx.showToast({
            title: '已经加载完数据了',
            icon: 'none',
            duration: 2000

          })
          return;
        }


        let jdata = pthis.data.list;
        //console.log(jdata);
        let ndata = response.data.data.rated;
        //console.log(ndata);

        jdata = jdata.concat(ndata)
        //console.log(jdata);
        pthis.setData({
          'list': jdata,
          'page': newpage
        });
      }
    });


  },

json配置

{
  "usingComponents": {},
  "onReachBottomDistance":50
}

PHP代码

    $pindex = max(1, intval($_GPC['page']));
    $psize = 10;
    $condition = 'uniacid = :uniacid and openid=:openid';
    $params = array(':uniacid' => $_W['uniacid'], ':openid' => $openid);

    $sql = 'SELECT * FROM ' . tablename('zhou_youx_integral_jilu') . ' where ' . $condition . ' ORDER BY id DESC LIMIT ' . (($pindex - 1) * $psize) . ',' . $psize;
    $list = pdo_fetchall($sql, $params);


    if (empty($list)) {
      $data['rated'] = '';
      $data['code'] = '120000';
      $data['msg'] = '成功';
      $data['data'] ='';
      return json_encode($data);

    }else{

          foreach ($list as $k=>&$v){

            $v['createtime'] = date("Y-m-d H:i",$v['createtime']);

          }


          $res['code'] = 120001;
          $res['msg'] = '成功';
          $res['data'] = $list;
          return  json_encode($res);

    }
赞(1)
未经允许不得转载:程序员中文网 » 微信小程序监听页面上拉加载
分享到: 更多 (0)
关于我们 免责申明 意见反馈 隐私政策
程序员中文网:公益在线网站,帮助学习者快速成长!
关注微信 技术交流
推荐文章
每天精选资源文章推送
推荐文章
随时随地碎片化学习
推荐文章
发现有趣的