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中寫(xiě)的內(nèi)容
reload: false,
status: 'more',
contentText: {
contentdown: '上拉加載更多~',
contentrefresh: '加載中',
contentnomore: '我是有底線的~'
},3 template里面寫(xiě)的內(nèi)容
<uni-load-more :status="status" :icon-size="14" :content-text="contentText" v-if="dataList.length > 0" />
4 請(qǐng)求接口成功之后,判斷加載狀態(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)//這里我是延遲一秒在加載方法有個(gè)loading效果,如果接口請(qǐng)求慢的話可以去掉
} else { //停止加載
this.status = 'noMore'
}
},uniapp - load-more觸底加載,下拉刷新
底部加載load-more(uni-ui組件)
三個(gè)狀態(tài):more、loading、nomore
- 觸底事件:onReachBottom
- 下拉刷新:onPullDownRefresh,停止下拉刷新uni.stopPullDownRefresh()
<template>
<view>
<!-- 底部加載,三個(gè)狀態(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, //記錄當(dāng)前頁(yè)碼
};
},
//觸底事件,請(qǐng)求數(shù)據(jù)、合并
onReachBottom() {
console.log('到底了到底了...');
this.status = 'loading';
this.getData(this.page + 1);
this.page += 1;
},
//下拉刷新,請(qǐng)求第一頁(yè)
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);
//如果頁(yè)數(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é)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
通過(guò)Element ui往頁(yè)面上加一個(gè)分頁(yè)導(dǎo)航條的方法
這篇文章主要介紹了通過(guò)Element ui往頁(yè)面上加一個(gè)分頁(yè)導(dǎo)航條的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-05-05
Vue2.0 v-for filter列表過(guò)濾功能的實(shí)現(xiàn)
今天小編就為大家分享一篇Vue2.0 v-for filter列表過(guò)濾功能的實(shí)現(xiàn),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-09-09
element-ui如何取消el-table的hover狀態(tài)(取消高亮顯示)
在一個(gè)項(xiàng)目中需要對(duì)element-ui的table組件進(jìn)行一些樣式的修改,其中就包括對(duì)hover效果的處理,下面這篇文章主要給大家介紹了關(guān)于element-ui如何取消el-table的hover狀態(tài)(取消高亮顯示)的相關(guān)資料,需要的朋友可以參考下2022-11-11
vue3 component is 不顯示的問(wèn)題及解決
這篇文章主要介紹了vue3 component is 不顯示的問(wèn)題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03

