欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信小程序實現(xiàn)上拉加載功能

 更新時間:2019年11月20日 14:52:43   作者:£AP︶ㄣOL◢◤LO  
這篇文章主要為大家詳細介紹了微信小程序實現(xiàn)上拉加載功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了微信小程序上拉加載的具體代碼,供大家參考,具體內容如下

demo.wxml  文件

<view wx:for="{{listdata}}" wx:key="listdata" class='listitem'>
 <view class='title'>{{ item.store_name }}</view>
 <image src='{{item.logo}}'></image>
</view>

<view class="load-more-wrap">
 <block wx:if="{{hasMore}}">
  <view class="load-content">
   <text class="weui-loading"/><text class="loading-text">玩命加載中</text>
  </view>
 </block>
 <block wx:else>
  <view class="load-content">
   <text>沒有更多內容了</text>
  </view>
 </block>
</view>

demo.js文件

Page({
 data: {
  listdata:[],  //數(shù)據(jù)
  paginated: '',
  //{total:"12", count: 10, more: 1} total數(shù)據(jù)總數(shù),count:當前分頁數(shù)據(jù)數(shù)據(jù),more:1表示還有,0表示無數(shù)據(jù)
  p:0, //當前分頁;默認第一頁
  hasMore:true //提示
 },
 onLoad: function (options) {
  var that = this;
  var p = that.data.p;
  this.loadmore();
 },
 onReachBottom:function(){
  var that = this;
  var paginated = that.data.paginated;
  if (paginated.more != 0) {
   this.loadmore();
  }else{
   that.setData({
    "hasMore": false
   })
  }
 },
 loadmore:function(){
  wx.showToast({
   title: "玩命加載中",
   icon: 'loading',
   duration: 1000
  })
  var that = this;
  var p = ++that.data.p;
  wx.request({
   url: 'xxx',
   data: {
    "json": JSON.stringify({
     "demo": "xxx", "p": p
    })
   },
   method: 'POST',
   header: {
    'content-type': 'application/x-www-form-urlencoded'
   },
   success:function(res){
    if (res.data.data != 0) {
     that.setData({
      "listdata": that.data.listdata.concat(res.data.data), //加載數(shù)據(jù)
      "paginated": res.data.paginated, //{total:"12", count: 10, more: 1} 此處主要用于上拉加載是否加載數(shù)據(jù)
      "p":p
     })
    } else {
     that.setData({
      "hasMore":false
     })
    }
   }
  })
 }
})

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論