網站首頁 編程語言 正文
下拉刷新的實現步驟(代碼解釋詳細,通俗易懂)
1.pages.json文件中,globalStyle里面開啟下拉刷新,屬性為true
{
"pages": [
{
"path": "pages/index/index"
},
{
"path": "pages/search/search"
},
{
"path": "pages/cart/cart"
},
{
"path": "pages/member/member"
}
,{
"path" : "pages/goods/goods",
"style" :
{
"navigationBarTitleText": ""
// "enablePullDownRefresh": true
}
}
],
"globalStyle": {
"navigationBarTextStyle": "white",
"navigationBarTitleText": "多抓魚",
"navigationBarBackgroundColor": "#003153",
"enablePullDownRefresh": true,
"backgroundColor": "#F8F8F8",
"app-plus": {
"background": "#efeff4"
}
},
"tabBar": {
//列表的順序決定圖標的順序
"list": [
{
"pagePath":"pages/index/index",
"text":"首頁",
"iconPath":"static/icon/home.png",
"selectedIconPath":"static/icon/home-active.png"
},
{
"pagePath":"pages/search/search",
"text":"搜索",
"iconPath":"static/icon/news.png",
"selectedIconPath":"static/icon/news-active.png"
},
{
"pagePath":"pages/cart/cart",
"text":"購物車",
"iconPath":"static/icon/cart.png",
"selectedIconPath":"static/icon/cart-active.png"
},
{
"pagePath":"pages/member/member",
"text":"會員",
"iconPath":"static/icon/member.png",
"selectedIconPath":"static/icon/member-active.png"
}
]
}
}
2.onPullDownRefresh是頁面周期函數,下拉操作會觸發該函數
goods.vue中
methods: {
async getGoodsInfo(callback){
const res = await this.$myRequest({
url: "/goods/search?pageIndex="+this.pageIndex,
method: 'get',
})
//對象擴展運算符,將兩個數組合并成一個
this.goods = [...this.goods,...res.data.message.goods];
this.total = res.data.message.total;
this.pagenum = res.data.message.pagenum;
console.log("total",this.goods.length)
//傳入回調函數就執行
callback && callback()
}
},
onPullDownRefresh() {
console.log('下拉刷新了')
this.pageindex = 1
this.goods = []
this.flag = false
setTimeout(()=>{
this.getGoodsInfo(()=>{
uni.stopPullDownRefresh()
})
},1000)
}
上拉加載
頁面周期函數,頁面拉到底自動觸發。
methods: {
async getGoodsInfo(callback){
const res = await this.$myRequest({
url: "/goods/search?pageIndex="+this.pageIndex,
method: 'get',
})
this.goods = [...this.goods,...res.data.message.goods];
this.total = res.data.message.total;
this.pagenum = res.data.message.pagenum;
console.log("total",this.goods.length)
callback && callback()
}
},
onReachBottom() {
if(this.goods.lenth < 20*this.pageIndex){
return this.flag = true;
}
this.pageIndex++;
this.getGoodsInfo();
},
原文鏈接:https://blog.csdn.net/qiuyushuofeng/article/details/125420842
- 上一篇:數組的遍歷方法有哪些
- 下一篇:uniapp創建自定義組件報錯
相關推薦
- 2024-03-21 Springboot實現接口傳輸加解密
- 2022-05-11 pg分區表的實踐
- 2022-03-05 CentOS系統下安裝及配置JDK介紹_Linux
- 2022-03-21 golang?調用c語言動態庫方式實現_Golang
- 2023-01-18 pip?search報錯問題及解決_python
- 2023-03-27 詳解如何在React中優雅的使用addEventListener_React
- 2022-10-22 關于分布式鎖的三種實現方式_Redis
- 2022-10-03 使用useImperativeHandle時父組件第一次沒拿到子組件的問題_React
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支