本篇文章講述了微信小程式實作下拉載入和上拉刷新,大家對微信小程式實作下拉載入和上拉刷新不了解的話或是對微信小程式實作下拉載入和上拉刷新感興趣的話那麼我們就一起來看看這篇文章吧, 好了廢話少說進入正題吧
微信小程式下拉刷新上拉加載的兩種實作方法
#方法一:onPullDownRefresh和onReachBottom方法實作小程式下拉載入和上拉刷新
首先要在json檔案裡設定window屬性
# 屬性 | ## 類型 | ## enablePullDownRefresh |
Boolean | 是否開啟下拉刷新,詳見頁面相關事件處理函數。 | 設定js裡onPullDownRefresh與onReachBottom方法 |
屬性 屬性
類型 | 描述 | onPull |
#onPull#DownRe | #function | 頁面相關事件處理函數-監聽使用者下拉動作 |
onReachBottom | function | 頁面上拉觸發底事件的處理函數 |
下拉載入說明:
當處理完資料刷新後,wx.stopPullDownRefresh可以停止目前頁面的下拉刷新。
onPullDownRefresh(){ console.log('--------下拉刷新-------') wx.showNavigationBarLoading() //在标题栏中显示加载 wx.request({ url: 'https://URL', data: {}, method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT // header: {}, // 设置请求的 header success: function(res){ // success }, fail: function() { // fail }, complete: function() { // complete wx.hideNavigationBarLoading() //完成停止加载 wx.stopPullDownRefresh() //停止下拉刷新 } })
方法二:
在scroll-view裡設定bindscrolltoupper和bindscrolltolower實作微信小程式下拉
屬性 | 型別 | |
bindscrolltoupper | EventHandle | 捲動到頂部/左邊,會觸發scrolltoupper 事件 |
bindscrolltolower | EventHandle | 捲動到底部/右邊,會觸發scrolltolower 事件 |
index.js
#
var url = "http://www.imooc.com/course/ajaxlist"; var page =0; var page_size = 5; var sort = "last"; var is_easy = 0; var lange_id = 0; var pos_id = 0; var unlearn = 0; // 请求数据 var loadMore = function(that){ that.setData({ hidden:false }); wx.request({ url:url, data:{ page : page, page_size : page_size, sort : sort, is_easy : is_easy, lange_id : lange_id, pos_id : pos_id, unlearn : unlearn }, success:function(res){ //console.info(that.data.list); var list = that.data.list; for(var i = 0; i < res.data.list.length; i++){ list.push(res.data.list[i]); } that.setData({ list : list }); page ++; that.setData({ hidden:true }); } }); } Page({ data:{ hidden:true, list:[], scrollTop : 0, scrollHeight:0 }, onLoad:function(){ // 这里要注意,微信的scroll-view必须要设置高度才能监听滚动事件,所以,需要在页面的onLoad事件中给scroll-view的高度赋值 var that = this; wx.getSystemInfo({ success:function(res){ that.setData({ scrollHeight:res.windowHeight }); } }); loadMore(that); }, //页面滑动到底部 bindDownLoad:function(){ var that = this; loadMore(that); console.log("lower"); }, scroll:function(event){ //该方法绑定了页面滚动时的事件,我这里记录了当前的position.y的值,为了请求数据之后把页面定位到这里来。 this.setData({ scrollTop : event.detail.scrollTop }); }, topLoad:function(event){ // 该方法绑定了页面滑动到顶部的事件,然后做上拉刷新 page = 0; this.setData({ list : [], scrollTop : 0 }); loadMore(this); console.log("lower"); } })
index.wxss
##/**index.wxss**/
.userinfo {
display: flex;
flex-direction: column;
align-items: center;
}
.userinfo-avatar {
width: 128rpx;
height: 128rpx;
margin: 20rpx;
border-radius: 50%;
}
.userinfo-nickname {
color: #aaa;
}
.usermotto {
margin-top: 200px;
}
/**/
scroll-view {
width: 100%;
}
.item {
width: 90%;
height: 300rpx;
margin: 20rpx auto;
background: brown;
overflow: hidden;
}
.item .img {
width: 430rpx;
margin-right: 20rpx;
float: left;
}
.title {
font-size: 30rpx;
display: block;
margin: 30rpx auto;
}
.description {
font-size: 26rpx;
line-height: 15rpx;
}
以上就是本篇文章的所有內容,大家要是還不太了解的話,可以自己多實現兩邊就很容易掌握了哦!
以上是微信小程式實作下拉載入和上拉刷新詳細講解的詳細內容。更多資訊請關注PHP中文網其他相關文章!

TheSecretTokeEpingAphp-PowerEdwebSiterUnningSmoothlyShyunderHeavyLoadInVolvOLVOLVOLDEVERSALKEYSTRATICES:1)emplactopCodeCachingWithOpcachingWithOpCacheToreCescriptexecution Time,2)使用atabasequercachingCachingCachingWithRedataBasEndataBaseLeSendataBaseLoad,3)

你應該關心DependencyInjection(DI),因為它能讓你的代碼更清晰、更易維護。 1)DI通過解耦類,使其更模塊化,2)提高了測試的便捷性和代碼的靈活性,3)使用DI容器可以管理複雜的依賴關係,但要注意性能影響和循環依賴問題,4)最佳實踐是依賴於抽象接口,實現鬆散耦合。

是的,優化papplicationispossibleandessential.1)empartcachingingcachingusedapcutorediucedsatabaseload.2)優化的atabaseswithexing,高效Quereteries,and ConconnectionPooling.3)EnhanceCodeWithBuilt-unctions,避免使用,避免使用ingglobalalairaiables,並避免使用

theKeyStrategiestosigantificallyBoostPhpaPplicationPerformenCeare:1)UseOpCodeCachingLikeLikeLikeLikeLikeCacheToreDuceExecutiontime,2)優化AtabaseInteractionswithPreparedStateTementStatementStatementAndProperIndexing,3)配置

aphpdepentioncontiveContainerIsatoolThatManagesClassDeptions,增強codemodocultion,可驗證性和Maintainability.itactsasaceCentralHubForeatingingIndections,因此reducingTightCightTightCoupOulplingIndeSingantInting。

選擇DependencyInjection(DI)用於大型應用,ServiceLocator適合小型項目或原型。 1)DI通過構造函數注入依賴,提高代碼的測試性和模塊化。 2)ServiceLocator通過中心註冊獲取服務,方便但可能導致代碼耦合度增加。

phpapplicationscanbeoptimizedForsPeedAndeffificeby:1)啟用cacheInphp.ini,2)使用preparedStatatementSwithPdoforDatabasequesies,3)3)替換loopswitharray_filtaray_filteraray_maparray_mapfordataprocrocessing,4)conformentnginxasaseproxy,5)

phpemailvalidation invoLvesthreesteps:1)格式化進行regulareXpressecthemailFormat; 2)dnsvalidationtoshethedomainhasavalidmxrecord; 3)


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

記事本++7.3.1
好用且免費的程式碼編輯器

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

SublimeText3 Linux新版
SublimeText3 Linux最新版

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!