uni-app實現(xiàn)數(shù)據(jù)下拉刷新功能實例
uni-app上拉加載更多功能:http://www.fzitv.net/article/257733.htm
uni-app數(shù)據(jù)下拉刷新
在 pages.json 配置文件中,為當(dāng)前的 goods_list 頁面單獨開啟下拉刷新效果:
"subPackages": [{
"root": "subpkg",
"pages": [{
"path": "goods_detail/goods_detail",
"style": {}
}, {
"path": "goods_list/goods_list",
"style": {
"onReachBottomDistance": 150,
"enablePullDownRefresh": true,
"backgroundColor": "#F8F8F8"
}
}, {
"path": "search/search",
"style": {}
}]
}]監(jiān)聽頁面的 onPullDownRefresh 事件處理函數(shù):
// 下拉刷新的事件
onPullDownRefresh() {
// 1. 重置關(guān)鍵數(shù)據(jù)
this.queryObj.pagenum = 1
this.total = 0
this.isloading = false
this.goodsList = []
// 2. 重新發(fā)起請求
this.getGoodsList(() => uni.stopPullDownRefresh())
}
修改 getGoodsList 函數(shù),接收 cb 回調(diào)函數(shù)并按需進行調(diào)用:
// 獲取商品列表數(shù)據(jù)的方法
async getGoodsList(cb) {
this.isloading = true
const { data: res } = await uni.$http.get('/api/public/v1/goods/search', this.queryObj)
this.isloading = false
// 只要數(shù)據(jù)請求完畢,就立即按需調(diào)用 cb 回調(diào)函數(shù)
cb && cb()
if (res.meta.status !== 200) return uni.$showMsg()
this.goodsList = [...this.goodsList, ...res.message.goods]
this.total = res.message.total
}
uni-app上拉加載更多功能:http://www.fzitv.net/article/257733.htm
附:uni.startPullDownRefresh(OBJECT)
通過 uni.startPullDownRefresh(OBJECT) 開始下拉刷新,調(diào)用后觸發(fā)下拉刷新動畫,效果與用戶手動下拉刷新一致。
<template>
<view>
<view v-for="(item,index) of list" :key="index">
{{item}}
</view>
<button @click="pullDown">點擊觸發(fā)下拉刷新</button>
</view>
</template>
<script>
export default {
data() {
return {
list: [1, 2, 3, 4, 5]
}
},
methods: {
pullDown() {
//觸發(fā)下拉刷新
uni.startPullDownRefresh()
}
},
onPullDownRefresh() {
console.log("觸發(fā)下拉刷新")
setTimeout(() => {
this.list = [1, 2, 3, 5, 3, 2]
//關(guān)閉下拉刷新
uni.stopPullDownRefresh()
}, 2000)
}
}
</script>
<style>
</style>
總結(jié)
到此這篇關(guān)于uni-app實現(xiàn)數(shù)據(jù)下拉刷新功能的文章就介紹到這了,更多相關(guān)uni-app數(shù)據(jù)下拉刷新內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
url特殊字符編碼encodeURI?VS?encodeURIComponent分析
這篇文章主要介紹了url特殊字符編碼encodeURI?VS?encodeURIComponent分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-09-09
詳解小程序BackgroundAudioManager踩坑之旅
這篇文章主要介紹了詳解小程序BackgroundAudioManager踩坑之旅,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12
JS 中使用Promise 實現(xiàn)紅綠燈實例代碼(demo)
本文通過實例代碼給大家介紹了JS 中使用Promise 實現(xiàn)紅綠燈效果,在文中給大家介紹了一個promise用法例子,需要的朋友可以參考下2017-10-10
JavaScript操作XML/HTML比較常用的對象屬性集錦
本文給大家介紹javascript操作xml/html比較常用的對象屬性,涉及到j(luò)s對象屬性相關(guān)知識,對JavaScript操作XML/HTML比較常用的對象屬性感興趣的朋友可以參考下本文2015-10-10
JS拖動鼠標畫出方框?qū)崿F(xiàn)鼠標選區(qū)的方法
這篇文章主要介紹了JS拖動鼠標畫出方框?qū)崿F(xiàn)鼠標選區(qū)的方法,涉及javascript鼠標事件及頁面元素樣式的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-08-08

