uni-app實現(xiàn)數(shù)據(jù)下拉刷新功能實例
uni-app上拉加載更多功能:http://www.dbjr.com.cn/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.dbjr.com.cn/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)文章
Javascript highcharts 餅圖顯示數(shù)量和百分比實例代碼
這篇文章主要介紹了Javascript highcharts 餅圖顯示數(shù)量和百分比實例代碼的相關(guān)資料,這里附有實例代碼,需要的朋友可以參考下2016-12-12JS+HTML實現(xiàn)的圓形可點擊區(qū)域示例【3種方法】
這篇文章主要介紹了JS+HTML實現(xiàn)的圓形可點擊區(qū)域,結(jié)合實例形式分析了javascript結(jié)合HTML元素屬性實現(xiàn)一個圓形的可點擊區(qū)域相關(guān)操作技巧,需要的朋友可以參考下2018-08-08