小小記錄一下
(一) 下拉刷新
<!-- page.json 中設置一下 --> "enablePullDownRefresh": true, <!-- 當前頁處理下拉時候的事件 --> onPullDownRefresh(){ }, <!-- 處理完成后關閉下拉效果 --> uni.stopPullDownRefresh(); setTimeout(function () { uni.stopPullDownRefresh(); }, 2000);
(二) 上拉加載
<!-- data 里自定義一個空數組 --> list: [] <!-- 調接口的時候 用 ... 拼接 --> this.list.push(...data); <!-- 分頁的時候直接 page++ 再調接口就好 --> onReachBottom() { if (!this.nomore) { this.page++; this.getData(); } } <!-- 可以先用 if 判斷下條件,然后再確定是否要加載(這樣可以少請求接口,更方便) -->