這篇文章主要為大家詳細(xì)介紹了微信小程序加載更多,點(diǎn)擊查看更多功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了微信小程序加載更多功能實(shí)現(xiàn)的具體代碼,供大家參考,具體內(nèi)容如下
微信小程序加載更多,是將之前的數(shù)據(jù)和點(diǎn)擊加載后請(qǐng)求的數(shù)據(jù)用concat拼接在一起并執(zhí)行setData,下面是一個(gè)簡(jiǎn)單的栗子:
index.wxml代碼如下
<view wx:for="{{duanziInfo}}" wx:for-item="name" wx:for-index="id"> <view class="duanzi-view"> <view class="duanzi-content"> <text class="dz-content">{{name.content}}</text> </view> </view> </view> <view class="button-wrapper"> <button type="default" size="default" loading="{{loading}}" disabled="{{disabled}}" bindtap="setLoading"> {{loadText}} </button> </view>
登錄后復(fù)制
加載更多按鈕綁定setLoading
index.js文件代碼如下
Page({ data: { loadText:'加載更多', duanziInfo:[] }, //初始化請(qǐng)求 onLoad: function (res) { var that = this //內(nèi)容 wx.request({ url: 'http://xxxxx.com/index.php?m=Industry&a=getDuanziInfo', data: {token:token}, method: 'GET', success: function(res){ console.log(res.data.result) //打印初始化數(shù)據(jù) that.setData({ duanziInfo:res.data.result }) } }) }, //加載更多 setLoading: function(e) { var duanziInfoBefore = this.data.duanziInfo var that = this wx.showToast({ //期間為了顯示效果可以添加一個(gè)過(guò)度的彈出框提示“加載中” title: '加載中', icon: 'loading', duration: 200 }) wx.request({ url: 'http://xxxxx.com/index.php?m=Industry&a=getDuanziInfo', data: {token:token}, method: 'GET', success: function(res){ console.log(duanziInfoBefore.concat(res.data.result)) //打印拼接之后數(shù)據(jù) that.setData({ loadText:"數(shù)據(jù)請(qǐng)求中", loading:true, duanziInfo:duanziInfoBefore.concat(res.data.result), loadText:"加載更多", loading:false, }) } }) } })
登錄后復(fù)制
初始化和加載更多中的打印數(shù)據(jù)如下
(以上是點(diǎn)擊查看更多,還可以根據(jù)距離視圖區(qū)域的距離來(lái)加載更多,具體實(shí)現(xiàn)是將視圖用
標(biāo)簽,并給其一個(gè)固定高度,在給定參數(shù)中設(shè)置距離像素觸發(fā)事件。具體文檔:https://mp.weixin.qq.com/debug/wxadoc/dev/component/scroll-view.html?t=20161122)
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,更多相關(guān)內(nèi)容請(qǐng)關(guān)注PHP中文網(wǎng)!
相關(guān)推薦:
以上就是關(guān)于微信小程序加載更多和點(diǎn)擊查看更多的代碼的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注有卡有網(wǎng)。