微信小程序頁(yè)面滑動(dòng)屏幕加載數(shù)據(jù)效果
滑動(dòng)屏幕加載數(shù)據(jù)是任何小程序中都會(huì)用到的功能,本文我就將這個(gè)功能整理給大家,希望對(duì)大家有意。我們先看看效果圖:
創(chuàng)建目錄
首先我們現(xiàn)在項(xiàng)目中創(chuàng)建資訊目錄,以下是我自己創(chuàng)建的目錄,大家可以根據(jù)自己的需求創(chuàng)建。如圖所示:
創(chuàng)建lists.js文件
以下是lists.js代碼
var app = getApp() Page({ data: { newsList: [], lastid: 0, toastHidden: true, confirmHidden: true, isfrist: 1, loadHidden: true, moreHidden: 'none', msg: '沒(méi)有更多文章了' }, loadData: function (lastid) { //顯示出加載中的提示 this.setData({ loadHidden: false }) var limit = 10 var that = this wx.request({ url: 'http://127.0.0.1:9090/hpm_bill_web/news/getnewslist', //數(shù)據(jù)接口 data: { lastid: lastid, limit: limit }, header: { 'Content-Type': 'application/json' }, success: function (res) { if (!res.data) { that.setData({ toastHidden: false }) that.setData({ moreHidden: 'none' }) return false } var len = res.data.length var oldLastid = lastid if(len != 0) { that.setData({ lastid: res.data[len - 1].id }) } else { that.setData({ toastHidden: false}) } var dataArr = that.data.newsList var newData = dataArr.concat(res.data); if (oldLastid == 0) { wx.setStorageSync('CmsList', newData) } that.setData({ newsList: newData }) that.setData({ moreHidden: '' }) }, fail: function (res) { if (lastid == 0) { var newData = wx.getStorageSync('CmsList') if(newData) { that.setData({ newsList: newData }) that.setData({ moreHidden: '' }) var len = newData.length if (len != 0) { that.setData({ lastid: newData[len - 1].id }) } else { that.setData({ toastHidden: false }) } console.log('data from cache'); } } else { that.setData({ toastHidden: false, moreHidden: 'none', msg: '當(dāng)前網(wǎng)格異常,請(qǐng)稍后再試' }) } }, complete: function () { //顯示出加載中的提示 that.setData({ loadHidden: true }) } }) }, loadMore: function (event) { var id = event.currentTarget.dataset.lastid var isfrist = event.currentTarget.dataset.isfrist var that = this wx.getNetworkType({ success: function (res) { var networkType = res.networkType // 返回網(wǎng)絡(luò)類(lèi)型2g,3g,4g,wifi if (networkType != 'wifi' && isfrist == '1') { that.setData({ confirmHidden: false }) } } }) this.setData({ isfrist: 0 }) this.loadData(id); }, onLoad: function () { var that = this this.loadData(0); }, toastChange: function () { this.setData({ toastHidden: true }) }, modalChange: function () { this.setData({ confirmHidden: true }) } })
創(chuàng)建頁(yè)面文件(lists.wxml)
<view class="warp"> <!-- 文章列表模板 begin --> <template name="items"> <navigator url="../../pages/detail/detail?id={{id}}" hover-class="navigator-hover"> <view class="imgs"> <image src="{{image}}" class="in-img" background-size="cover" model="scaleToFill"></image> </view> <view class="infos"> <view class="title">{{name}}</view> <view class="dates">{{createtime}}</view> </view> </navigator> </template> <!-- 文章列表模板 end --> <!-- 循環(huán)輸出列表 begin --> <view wx:for="{{newsList}}" class="list"> <template is="items" data="{{...item}}" /> </view> <!-- 循環(huán)輸出列表 end --> <loading hidden="{{loadHidden}}" bindchange="loadChange"> 數(shù)據(jù)加載中... </loading> <view bindtap="loadMore" data-lastid="{{lastid}}" data-isfrist="{{isfrist}}" class="loadMore" style="display:{{moreHidden}}">加載更多</view> <toast hidden="{{toastHidden}}" bindchange="toastChange" duration="3000">{{msg}}</toast> <modal title="溫馨提示" no-cancel confirm-text="明確" cancel-text="關(guān)閉" hidden="{{confirmHidden}}" bindconfirm="modalChange" bindcancel="modalChange">你當(dāng)前不在在WIFI網(wǎng)格下下,會(huì)產(chǎn)生流量費(fèi)用</modal> </view>
創(chuàng)建頁(yè)面樣式(lists.wxss)
.warp {height:100%;display:flex;flex-direction: column;padding:20rpx;} navigator {overflow: hidden;} .list {margin-bottom:20rpx;height:200rpx;position:relative;} .imgs{float:left;} .imgs image {display:block;width:200rpx;height:200rpx;} .infos {float:left;width:480rpx;height:200rpx;padding:20rpx 0 0 20rpx} .title {font-size:20px; font-family: Microsoft Yahei} .dates {font-size:16px;color: #aaa; position: absolute;bottom:0;} .loadMore {text-align: center; margin:30px;color:#aaa;font-size:16px;}
通過(guò)以上代碼就能實(shí)現(xiàn)在屏幕上滑動(dòng)顯示數(shù)據(jù)的功能。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 微信小程序?qū)崿F(xiàn)卡片左右滑動(dòng)效果的示例代碼
- 微信小程序左右滑動(dòng)的實(shí)現(xiàn)代碼
- 微信小程序滾動(dòng)Tab實(shí)現(xiàn)左右可滑動(dòng)切換
- 微信小程序圖片橫向左右滑動(dòng)案例
- 微信小程序左右滑動(dòng)切換頁(yè)面詳解及實(shí)例代碼
- 微信小程序側(cè)邊欄滑動(dòng)特效(左右滑動(dòng))
- 小程序?qū)崿F(xiàn)點(diǎn)擊tab切換左右滑動(dòng)
- 小程序?qū)崿F(xiàn)日歷左右滑動(dòng)效果
- 微信小程序之滑動(dòng)頁(yè)面隱藏和顯示組件功能的實(shí)現(xiàn)代碼
- 微信小程序?qū)崿F(xiàn)頁(yè)面左右滑動(dòng)
相關(guān)文章
原生JS實(shí)現(xiàn)的多個(gè)彩色小球跟隨鼠標(biāo)移動(dòng)動(dòng)畫(huà)效果示例
這篇文章主要介紹了原生JS實(shí)現(xiàn)的多個(gè)彩色小球跟隨鼠標(biāo)移動(dòng)動(dòng)畫(huà)效果,涉及javascript事件響應(yīng)、頁(yè)面元素屬性動(dòng)態(tài)修改及隨機(jī)數(shù)應(yīng)用等相關(guān)操作技巧,需要的朋友可以參考下2018-02-02微信小程序開(kāi)發(fā)之a(chǎn)nimation循環(huán)動(dòng)畫(huà)實(shí)現(xiàn)的讓云朵飄效果
這篇文章主要介紹了微信小程序開(kāi)發(fā)之a(chǎn)nimation循環(huán)動(dòng)畫(huà)實(shí)現(xiàn)的讓云朵飄效果,結(jié)合實(shí)例形式分析了animation結(jié)合js時(shí)間函數(shù)實(shí)現(xiàn)循環(huán)動(dòng)畫(huà)效果的具體步驟與相關(guān)操作技巧,需要的朋友可以參考下2017-07-07用DIV完美模擬createPopup 彈出窗口(腳本之家修正版),支持Firefox,ie,chrome
最近要重構(gòu)公司的一個(gè)站,有一個(gè)拾色器只支持IE,不支持FIREFOX CHROME等瀏覽器,花了點(diǎn)時(shí)間對(duì)照原來(lái)的重寫(xiě)了個(gè)。完美實(shí)現(xiàn)createPopup方法的彈窗效果,歡迎大家拍磚!2009-09-09如何使用JavaScript和XLSX.js將數(shù)據(jù)導(dǎo)出為Excel文件
這篇文章主要給大家介紹了關(guān)于如何使用JavaScript和XLSX.js將數(shù)據(jù)導(dǎo)出為Excel文件的相關(guān)資料,xlsx.js基于JavaScript的Excel文件讀寫(xiě)庫(kù) 如果你需要在瀏覽器端處理Excel文件,那么xlsx.js可能是一個(gè)不錯(cuò)的選擇,需要的朋友可以參考下2024-05-05javascript設(shè)計(jì)模式之module(模塊)模式
這篇文章主要為大家詳細(xì)介紹了javascript設(shè)計(jì)模式之module(模塊)模式 ,感興趣的小伙伴們可以參考一下2016-08-08Javascript函數(shù)技巧學(xué)習(xí)
這篇文章主要介紹了Javascript函數(shù)技巧學(xué)習(xí),文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的朋友可以參考一下2022-07-07IE和Firefox之間在JavaScript語(yǔ)法上的差異
這篇文章主要為大家詳細(xì)介紹了IE和Firefox之間在JavaScript語(yǔ)法上的差異,在JavaScript語(yǔ)法上不同的7個(gè)方面,感興趣的小伙伴們可以參考一下2016-04-04js實(shí)現(xiàn)隨機(jī)抽獎(jiǎng)
這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)隨機(jī)抽獎(jiǎng)功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-03-03javascript實(shí)現(xiàn)跨域的方法匯總
這篇文章主要給大家匯總介紹了javascript實(shí)現(xiàn)跨域的方法的相關(guān)資料,需要的朋友可以參考下2015-06-06