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

微信小程序 列表的上拉加載和下拉刷新的實(shí)現(xiàn)

 更新時(shí)間:2017年04月01日 15:12:31   作者:請(qǐng)叫我小東子  
本文主要介紹了微信小程序中實(shí)現(xiàn)列表的上拉加載和下拉刷新的方法。具有很好的參考價(jià)值。下面跟著小編一起來看下吧

微信小程序可謂是9月21號(hào)之后最火的一個(gè)名詞了,一經(jīng)出現(xiàn)真是轟炸了整個(gè)開發(fā)人員,當(dāng)然很多App開發(fā)人員有了一個(gè)擔(dān)心,微信小程序的到來會(huì)不會(huì)讓移動(dòng)端App顛覆,讓移動(dòng)端的程序員失業(yè),身為一個(gè)Android開發(fā)者我是不相信的,即使有,那也是需要個(gè)一兩年的過度和打磨才能實(shí)現(xiàn)的吧。

不管微信小程序是否能顛覆當(dāng)今的移動(dòng)開發(fā)格局,我們都要積極向上的心態(tài)去接收,去學(xué)習(xí)。不排斥新技術(shù),所以,心動(dòng)不如行動(dòng),趕緊先搭建一個(gè)微信小程序開發(fā)工具。那么接下來就讓我們來開始學(xué)習(xí)列表的上拉加載和下拉刷新的實(shí)現(xiàn)吧(通過聚合數(shù)據(jù)平臺(tái)獲取微信新聞)。

1.介紹幾個(gè)組件

1.1 scroll-view 組件

注意:使用豎向滾動(dòng)時(shí),需要給一個(gè)固定高度,通過 WXSS 設(shè)置 height。

1.2 image組件

注意:mode有12種模式,其中3種是縮放模式,9種是裁剪模式。

1.3 Icon組件


iconType: [ 
‘success', ‘info', ‘warn', ‘waiting', ‘safe_success', ‘safe_warn', 
‘success_circle', ‘success_no_circle', ‘waiting_circle', ‘circle', ‘download', 
‘info_circle', ‘cancel', ‘search', ‘clear' 
]

2.列表的上拉加載和下拉刷新的實(shí)現(xiàn)

2.1先來張效果圖

2.2邏輯很簡(jiǎn)單,直接上代碼

2.2.1 detail.wxml 布局文件

<loading hidden="{{hidden}}" bindchange="loadingChange">
 加載中...
 </loading> 
 <scroll-view scroll-y="true" style="height: 100%;" bindscrolltolower="loadMore" bindscrolltoupper="refesh">
 <view wx:if="{{hasRefesh}}" style="display: flex;flex-direction: row;align-items: center;align-self: center;justify-content: center;">
 <icon type="waiting" size="45"/><text>刷新中...</text></view>
 <view wx:else style="display:none" ><text></text></view>
 <view class="lll" wx:for="{{list}}" wx:for-item="item" bindtap="bindViewTap" 
 data-title="{{item.title}}" >
 <image style=" width: 50px;height: 50px;margin: 20rpx;" src="{{item.firstImg}}" ></image>
 <view class="eee" > 
 <view style="margin:5px;font-size:8px"> 標(biāo)題:{{item.title}}</view>
 <view style="margin:5px;color:red;font-size:6px"> 來源:{{item.source}}</view>
 </view>
</view>
<view class="tips1">
 <view wx:if="{{hasMore}}" style="display: flex;flex-direction: row;align-items: center;align-self: center;justify-content: center;">
 <icon type="waiting" size="45"/><text>玩命的加載中...</text></view>
 <view wx:else><text>沒有更多內(nèi)容了</text></view>
 </view>
 </scroll-view>

2.2.1 detail.js邏輯代碼文件

var network_util = require('../../utils/network_util.js');
var json_util = require('../../utils/json_util.js');
Page({
 data:{
 // text:"這是一個(gè)頁面"
 list:[],
 dd:'',
 hidden:false,
 page: 1,
 size: 20,
 hasMore:true,
 hasRefesh:false
 },
 onLoad:function(options){
 var that = this;
 var url = 'http://v.juhe.cn/weixin/query?key=f16af393a63364b729fd81ed9fdd4b7d&pno=1&ps=10';
 network_util._get(url,
 function(res){
 that.setData({
 list:res.data.result.list,
 hidden: true,
 });
 },function(res){
 console.log(res);
 });
 },
 onReady:function(){
 // 頁面渲染完成
 },
 onShow:function(){
 // 頁面顯示
 },
 onHide:function(){
 // 頁面隱藏
 },
 onUnload:function(){
 // 頁面關(guān)閉
 },
 //點(diǎn)擊事件處理
 bindViewTap: function(e) {
 console.log(e.currentTarget.dataset.title);
 },
 //加載更多
 loadMore: function(e) {
 var that = this;
 that.setData({
 hasRefesh:true,});
 if (!this.data.hasMore) return
 var url = 'http://v.juhe.cn/weixin/query?key=f16af393a63364b729fd81ed9fdd4b7d&pno='+(++that.data.page)+'&ps=10';
 network_util._get(url,
 function(res){
 that.setData({
 list: that.data.list.concat(res.data.result.list),
 hidden: true,
 hasRefesh:false,
 });
 },function(res){
 console.log(res);
 })
},
//刷新處理
refesh: function(e) {
 var that = this;
 that.setData({
 hasRefesh:true,
 });
 var url = 'http://v.juhe.cn/weixin/query?key=f16af393a63364b729fd81ed9fdd4b7d&pno=1&ps=10';
 network_util._get(url,
 function(res){
 that.setData({
 list:res.data.result.list,
 hidden: true,
 page:1,
 hasRefesh:false,
 });
 },function(res){
 console.log(res);
 })
},
})

最后的效果:

關(guān)于新聞的詳情實(shí)現(xiàn),后面在實(shí)現(xiàn)

代碼地址:http://xiazai.jb51.net/201703/yuanma/WeiXinProject-master_jb51.rar

以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時(shí)也希望多多支持腳本之家!

相關(guān)文章

最新評(píng)論

册亨县| 北票市| 龙南县| 通化市| 河池市| 五河县| 陆河县| 乳源| 新泰市| 马关县| 秀山| 忻州市| 南丰县| 阿克陶县| 岳池县| 石棉县| 甘泉县| 榕江县| 洱源县| 讷河市| 光山县| 横峰县| 和龙市| 江永县| 射阳县| 徐州市| 绥化市| 云和县| 临漳县| 织金县| 时尚| 商都县| 府谷县| 田东县| 启东市| 孝义市| 通江县| 静安区| 石阡县| 大连市| 红原县|