目录

微信小程序-上拉触底加载更多

效果

说明

微信小程序当用户滑动到页面的最底部时加载更多数据,可以通过微信小程序官方接口文档提供的 onReachBottom 事件函数来实现,可通过该事件监听用户是否已经拉到最底部,实现相应的界面显示效果、数据加载。

实现

在 Page 页面中的 js 文件中,加入以下代码:

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    wx.showNavigationBarLoading() //在标题栏中显示加载
    wx.showLoading({
      title: '加载中...',
    })
    //模拟加载
    setTimeout(function()
    {
      // complete
      wx.hideNavigationBarLoading() //完成停止加载
      wx.hideLoading(); //完成刷新中的提示
    },1500);
  },

备注:加载数据写法应该如下示例

this.setData({dataList: this.data.dataList.concat(res.datas)});

在我测试中,在 setData 之外写,是无效的。


上一篇:«

下一篇: »


评论


Warning: Undefined variable $req in /www/wwwroot/wxzzz.com/wp-content/themes/quirk-wordpress-theme-master/functions.php on line 232

Warning: Undefined variable $commenter in /www/wwwroot/wxzzz.com/wp-content/themes/quirk-wordpress-theme-master/functions.php on line 233

Warning: Trying to access array offset on value of type null in /www/wwwroot/wxzzz.com/wp-content/themes/quirk-wordpress-theme-master/functions.php on line 233

Warning: Undefined variable $aria_req in /www/wwwroot/wxzzz.com/wp-content/themes/quirk-wordpress-theme-master/functions.php on line 233

Warning: Undefined variable $req in /www/wwwroot/wxzzz.com/wp-content/themes/quirk-wordpress-theme-master/functions.php on line 236

Warning: Undefined variable $commenter in /www/wwwroot/wxzzz.com/wp-content/themes/quirk-wordpress-theme-master/functions.php on line 237

Warning: Trying to access array offset on value of type null in /www/wwwroot/wxzzz.com/wp-content/themes/quirk-wordpress-theme-master/functions.php on line 237

Warning: Undefined variable $aria_req in /www/wwwroot/wxzzz.com/wp-content/themes/quirk-wordpress-theme-master/functions.php on line 238

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注