網站首頁 編程語言 正文
下拉刷新的實現步驟(代碼解釋詳細,通俗易懂)
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創建自定義組件報錯
相關推薦
- 2022-06-04 C#?XML基礎入門小結(XML文件內容增刪改查清)_C#教程
- 2022-06-10 C語言?模擬實現strlen函數詳解_C 語言
- 2022-07-30 如何重置CentOS 7的Root密碼?
- 2022-03-03 MacOS git pull / git clone Enter passphrase for ke
- 2023-03-19 Redis+Hbase+RocketMQ?實際使用問題案例講解_Redis
- 2023-07-22 使用log4j2為日志增加代碼行號
- 2021-11-21 關于.NET6?Minimal?API的使用方式詳解_實用技巧
- 2022-06-06 一文搞懂Redis中String數據類型_Redis
- 最近更新
-
- 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同步修改后的遠程分支