網(wǎng)站首頁 編程語言 正文
微信小程序,uniapp 實現(xiàn)觸底加載、自動請求接口合并數(shù)據(jù) onReachBottom()和scroll-view
文章目錄
- 微信小程序,uniapp 實現(xiàn)觸底加載、自動請求接口合并數(shù)據(jù) onReachBottom()和scroll-view
- onReachBottom
- onReachBottom用法
- 第一步 在page.json的style下設(shè)置
- 第二步 在對應(yīng)的頁面使用
- scroll-view
- 步驟一
- 步驟二
onReachBottom
uniapp官網(wǎng)onReachBottom的解釋是頁面滾動到底部的事件(不是scroll-view滾到底),常用于下拉下一頁數(shù)據(jù)。
onReachBottom用法
第一步 在page.json的style下設(shè)置
"pages": [
{
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "name",
"navigationBarBackgroundColor": "#fff",
"onReachBottomDistance": 150, //距離底部多遠(yuǎn)時觸發(fā) 單位是px
"enablePullDownRefresh":true //下拉刷新
}
},
]
第二步 在對應(yīng)的頁面使用
要寫在和data,method平級,和生命周期差不多
data() {},
methods:{},
onReachBottom(){
//里面加接口分頁,拿到數(shù)據(jù)后將數(shù)據(jù)push進(jìn)原來的數(shù)據(jù)里即可完成觸底加載,自動請求接口合并數(shù)據(jù)
// 讓頁碼值自增 +1
console.log("已經(jīng)到底咯,刷新下一頁");
this.params.pageNum += 1
// 重新獲取列表數(shù)據(jù)
apiGetAllPosts(this.params).then(res => {
this.allGoods.push(...res.data)
}).catch(err => {
console.log(err);
})
}
scroll-view
步驟一
在子組件外部,加上scroll-view 組件,并允許縱向滾動 使用豎向滾動時,需要給一個固定高度,通過 css設(shè)置高度。
<scroll-view @scrolltolower="getBottom" scroll-y="true" class=”elevend“>
//這里包含的是組件內(nèi)容
</scroll-view>
<style>
.elevend{
height: 90vh;
}
</style>
步驟二
在methods方法中,觸底加載的業(yè)務(wù)邏輯
methods: {
//觸底加載
getBottom(){
//里面加接口分頁,拿到數(shù)據(jù)后將數(shù)據(jù)push進(jìn)原來的數(shù)據(jù)里即可完成觸底加載,自動請求接口合并數(shù)據(jù)
// 讓頁碼值自增 +1
console.log("已經(jīng)到底咯,刷新下一頁");
this.params.pageNum += 1
// 重新獲取列表數(shù)據(jù)
apiGetAllPosts(this.params).then(res => {
this.allGoods.push(...res.data)
}).catch(err => {
console.log(err);
})
},
}
原文鏈接:https://blog.csdn.net/m0_63779088/article/details/128474006
- 上一篇:沒有了
- 下一篇:沒有了
相關(guān)推薦
- 2022-07-28 聊聊docker跨主機(jī)之間容器通信問題_docker
- 2023-02-06 C#基于時間輪調(diào)度實現(xiàn)延遲任務(wù)詳解_C#教程
- 2022-08-14 在WPF中使用多線程更新UI_C#教程
- 2022-03-23 shell中的流編輯器awk工作原理_linux shell
- 2022-11-12 基于Python制作一個匯率換算程序_python
- 2022-12-04 Jetpack?Compose慣性衰減動畫AnimateDecay詳解_Android
- 2023-02-15 PyQt5+PyQt5Designer的安裝步驟_python
- 2021-12-06 Windows下在CMD下執(zhí)行Go出現(xiàn)中文亂碼的解決方法_Golang
- 欄目分類
-
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支