uniapp小程序实现上拉加载更多


需求:后台聊天列表数据分页显示,前台需要根据页数来实现上拉加载显示更多页的内容

上拉组件使用的是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>

显示结果:

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM