最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

微信小程序?qū)崿F(xiàn)上拉加載功能示例【加載更多數(shù)據(jù)/觸底加載/點(diǎn)擊加載更多數(shù)據(jù)】

 更新時間:2020年05月29日 09:34:13   作者:TANKING  
這篇文章主要介紹了微信小程序?qū)崿F(xiàn)上拉加載功能,結(jié)合實(shí)例形式分析了微信小程序加載更多數(shù)據(jù)、觸底加載或點(diǎn)擊加載更多數(shù)據(jù)的相關(guān)實(shí)現(xiàn)技巧與操作注意事項(xiàng),需要的朋友可以參考下

本文實(shí)例講述了微信小程序?qū)崿F(xiàn)上拉加載功能。分享給大家供大家參考,具體如下:

開發(fā)需求

進(jìn)入頁面,加載初始數(shù)據(jù),當(dāng)向上拖動頁面至底部,自動加載新的數(shù)據(jù),即上拉加載更多數(shù)據(jù)。

演示

index.wxml

<!-- 數(shù)據(jù)列表 -->
<view wx:for="{{listdata}}" wx:key="listdata" class='listitem'>
 <view class='title'>{{item.title}}</view>
 <view class='title'>資源ID:{{item.id}}</view>
 <image src="{{item.coverimg}}" class='cover'></image>
</view>

<!-- 如果還有更多數(shù)據(jù)可以加載,則顯示玩命加載中 -->
<view class="load-more-wrap">
<block wx:if="{{hasMore}}">
 <view class="load-content">
 <text class="weui-loading"/><text class="loading-text">玩命加載中</text>
 </view>
</block>
<!-- 否則顯示沒有更多內(nèi)容了 -->
<block wx:else>
 <view class="load-content">
 <text>沒有更多內(nèi)容了</text>
 </view>
</block>
</view>

index.js

Page({
 data: {
 listdata:[], //數(shù)據(jù)
 moredata: '',
 p:0, //當(dāng)前分頁;默認(rèn)第一頁
 hasMore:true //提示
 },

 //加載初始數(shù)據(jù)
 onLoad: function (options) {
 var that = this;

 //初始頁面
 var p = that.data.p;
 this.loadmore();
 },

 //觸底事件
 onReachBottom:function(){
 var that = this;
 //檢查是否還有數(shù)據(jù)可以加載
 var moredata = that.data.moredata;
 //如果還有,則繼續(xù)加載
 if (moredata.more != 0) {
  this.loadmore();
  //如果沒有了,則停止加載,顯示沒有更多內(nèi)容了
 }else{
  that.setData({
  "hasMore": false
  })
 }
 },

 //發(fā)起請求
 loadmore:function(){

 //加載提示
 wx.showLoading({
  title: '加載中',
 })

 var that = this;
 //頁面累加
 var p = ++that.data.p;

 //請求服務(wù)器
 wx.request({
  url: '你的服務(wù)器/server.php?page=' + p,
  data: {
  "json": JSON.stringify({
   "p": p
  })
  },

  method: 'POST',
  header: {
  'content-type': 'application/x-www-form-urlencoded'
  },

  //請求成功,回調(diào)函數(shù)
  success:function(res){
  
  //隱藏加載提示
  wx.hideLoading();

  //判斷市局是否為空
  if (res.data != 0) {
   that.setData({
   //把新加載的數(shù)據(jù)追加到原有的數(shù)組
   "listdata": that.data.listdata.concat(res.data), //加載數(shù)據(jù)
   "moredata": res.data,
   "p":p
   })
  } else {
   that.setData({
   "hasMore":false
   })
  }
  }
 })
 }
})

說明

1、url修改為你的服務(wù)端鏈接,格式是

http:域名/目錄/?page=頁碼

例如:

http://www.baidu.com/api/data.php?page=1

頁碼是可變的,所以聲明一個變量p,所以就是

`url: 'http://www.baidu.com/api/data.php?page' + p,`

index.wxss

.listitem{
 width: 90%;
 height: 155px;
 background: rgba(0, 0, 0, 0.2);
 margin:10px auto;
 text-align: center;
 position: relative;
 color:#fff;
}

.listitem .cover{
 width:100%;
 height:155px;
 position: absolute;
 top: 0;
 left: 0;
 z-index: -100;
}

.load-more-wrap .load-content{
 text-align: center;
 margin:30px auto 30px;
 color:#ccc;
 font-size: 15px;
}

服務(wù)端返回的數(shù)據(jù)格式

返回json數(shù)組的形式,例如

[
 {"id":"1","title":"標(biāo)題1","coverimg":"url1"},
 {"id":"2","title":"標(biāo)題2","coverimg":"url2"},
 {"id":"3","title":"標(biāo)題3","coverimg":"url3"},
 {"id":"4","title":"標(biāo)題4","coverimg":"url4"},
 {"id":"5","title":"標(biāo)題5","coverimg":"url5"}
]

希望本文所述對大家微信小程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評論

城口县| 宁蒗| 滦平县| 科技| 察隅县| 建平县| 深圳市| 江都市| 扎囊县| 西畴县| 南木林县| 佳木斯市| 思南县| 堆龙德庆县| 奉化市| 十堰市| 康乐县| 商洛市| 祥云县| 景德镇市| 泗洪县| 天台县| 鱼台县| 罗甸县| 新龙县| 泰兴市| 临西县| 资阳市| 房山区| 广水市| 开原市| 革吉县| 乌拉特中旗| 衢州市| 拉萨市| 宝应县| 夏津县| 金平| 潜江市| 丰顺县| 嘉定区|