onPullDownRefresh模拟器正常触发方法,真机只能触发一次?
发布于 7 年前 作者 wei46 9469 次浏览 来自 官方Issues

json配置:

{

“enablePullDownRefresh”: true

}

js方法:

/**

  * 页面相关事件处理函数–监听用户下拉动作

  */

 onPullDownRefresh: function () {

   var currentPage = this.data.currentPage-1

   if(currentPage >= 1 ){

     this.setData({

       currentPage: currentPage

     })

     this.searchInfo(app.globalData.condition,currentPage)

   }else{

     wx.showToast({

       title: ‘已经是第一页了’,

       icon:‘loading’

     })

   }

 },

 /**

  * 页面上拉触底事件的处理函数

  */

 onReachBottom: function () {

   var currentPage = this.data.currentPage+1

   if (currentPage <= this.data.totalPage) {

     this.setData({

       currentPage: currentPage

     })

     this.searchInfo(app.globalData.condition, currentPage)

   } else {

     wx.showToast({

       title: ‘已经是最后一页了’,

       icon: ‘loading’

     })

   }

 },

2 回复

问题解决了,searchInfo异步请求方法写成this.searchInfo(app.globalData.condition, currentPage, wx.stopPullDownRefresh());

就是加了wx.stopPullDownRefresh()方法,下拉问题好了。。。

另外:onReachBottom得search方法改成:this.searchInfo(app.globalData.condition, currentPage,wx.pageScrollTo({scrollTop: 0}); 。。。

这样上拉、下拉就都好用了

应该提供一个代码片段,这样开发者更好定位

回到顶部