需求:后台聊天列表數據分頁顯示,前台需要根據頁數來實現上拉加載顯示更多頁的內容
上拉組件使用的是uniapp自帶的組件uni-load-more
<template> <view> <view v-for="(item, index) in List" :key="index"> <view class=""> {{item.data}} </view> </view> <uni-load-more :status="status" :content-text="contentText" /> </view> </template> <script> import uniLoadMore from '../../components/components/uni-load-more/uni-load-more.vue'; var page=1,newData=[]; export default { data() { return { List:[], status : 'loading', contentText: { contentdown: '上拉加載更多', contentrefresh: '加載中', contentnomore: '沒有更多' } } }, onLoad() { uni.request({ url:url, method:'GET', data:{}, success:res =>{ this.List=res.data; } }) }, // 上拉加載更多,onReachBottom上拉觸底函數 onReachBottom : function(){ this.status = 'more'; this.loadMoreFunc(); }, methods: { loadMoreFunc:function(){ //展示loading this.status = 'loading'; page++; uni.request({ url:url+page, method:'GET', data:{}, success:res =>{ newData=res.data; this.List = this.List.concat(newData); } ,fail: res => { this.status = 'noMore'; //沒有數據時顯示‘沒有更多’ } }) } }, components:{ uniLoadMore } } </script> <style> </style>
顯示結果: