uniapp中uni-load-more的使用方式
更新時間:2024年05月24日 09:01:03 作者:第7個前端
這篇文章主要介紹了uniapp中uni-load-more的使用方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
uniapp中uni-load-more使用
1 引入uniloadmore
import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
components: {uniLoadMore},2 data中寫的內(nèi)容
reload: false,
status: 'more',
contentText: {
contentdown: '上拉加載更多~',
contentrefresh: '加載中',
contentnomore: '我是有底線的~'
},3 template里面寫的內(nèi)容
<uni-load-more :status="status" :icon-size="14" :content-text="contentText" v-if="dataList.length > 0" />
4 請求接口成功之后,判斷加載狀態(tài),處理數(shù)據(jù)
success: (result) => {
this.totalCount = result.data.total
if (result.data.total > 0) {
const dataMap = result.data.list
this.dataList = this.reload ? dataMap : this.dataList.concat(dataMap);
this.reload = false;
} else {
this.dataList = [];
}
if (this.totalCount == this.dataList.length) {
this.reload = false;
this.status = 'noMore'
}
}5 監(jiān)控加載狀態(tài)
onReachBottom() {
if (this.totalCount > this.dataList.length) {
this.status = 'loading';
setTimeout(() => {
this.pageNum++
this.getMonthTask();//執(zhí)行的方法
}, 1000)//這里我是延遲一秒在加載方法有個loading效果,如果接口請求慢的話可以去掉
} else { //停止加載
this.status = 'noMore'
}
},uniapp - load-more觸底加載,下拉刷新
底部加載load-more(uni-ui組件)
三個狀態(tài):more、loading、nomore
- 觸底事件:onReachBottom
- 下拉刷新:onPullDownRefresh,停止下拉刷新uni.stopPullDownRefresh()
<template>
<view>
<!-- 底部加載,三個狀態(tài):more、loading、nomore -->
<uni-load-more :status="status"></uni-load-more>
</view>
</template>
<script>
export default {
data() {
return {
data: null,
status: 'more', //觸底加載狀態(tài)
page: 1, //記錄當前頁碼
};
},
//觸底事件,請求數(shù)據(jù)、合并
onReachBottom() {
console.log('到底了到底了...');
this.status = 'loading';
this.getData(this.page + 1);
this.page += 1;
},
//下拉刷新,請求第一頁
onPullDownRefresh() {
this.getData();
},
mounted() {
this.getData();
},
methods: {
getData(page = 1) {
uni.request({
url: 'https://xxxx.....',
method: 'GET',
data: { page: page },
success: res => {
console.log(res);
//如果頁數(shù)>1,需要拼接返回的數(shù)據(jù)
if (page > 1) {
res.data.result = [...this.data.result, ...res.data.result];
}
this.data = res.data;
uni.stopPullDownRefresh(); //拿到數(shù)據(jù)后,停止下拉刷新
},
fail: () => {},
complete: () => {}
});
},
},
};
</script>總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
通過Element ui往頁面上加一個分頁導(dǎo)航條的方法
這篇文章主要介紹了通過Element ui往頁面上加一個分頁導(dǎo)航條的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2021-05-05
Vue2.0 v-for filter列表過濾功能的實現(xiàn)
今天小編就為大家分享一篇Vue2.0 v-for filter列表過濾功能的實現(xiàn),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-09-09
element-ui如何取消el-table的hover狀態(tài)(取消高亮顯示)
在一個項目中需要對element-ui的table組件進行一些樣式的修改,其中就包括對hover效果的處理,下面這篇文章主要給大家介紹了關(guān)于element-ui如何取消el-table的hover狀態(tài)(取消高亮顯示)的相關(guān)資料,需要的朋友可以參考下2022-11-11

