微信小程序下拉列表加载更多数据(vue+uni-app+es6)详解

微信小程序下拉加载数据更多,使用到分页查询的原理,当用户下拉加载的时候触发事件,获取待处理数据 ,将待处理数据添加到数据组中。以下仅是自己实现的一种方式,可供参考
示例如下:

<template>
    <view>
        <view v-for="(item,index) in listData" :key="index">
            <view>{{item}}</view>
        </view>
        <view v-if="showMore">
            <uni-load-more :status="status" :content-text="contentText" color="#969799" @clickLoadMore="getMore()"/>
        </view>
        <view class="noData" v-if="!showMore ">暂无数据</view>
    </view>
</template>
<script>
    export default {
        data() {
            return {
                page: 1,
                pagesize: 10,
                content: "暂无数据",
                status: 'more',
                statusTypes: [
                    {
                        value: 'more',
                        text: '加载前'
                    }, {
                        value: 'loading',
                        text: '加载中'
                    }, {
                        value: 'noMore',
                        text: '没有更多'
                    }
                ],
                contentText: {
                    contentdown: '查看更多',
                    contentrefresh: '加载中',
                    contentnomore: '没有更多'
                },
                showMore: true,
                listData: [],    // 存放待处理数据
                upLoadData: [],  //存放数据组
            }
        },
        onLoad(option) {
            //获取初始化数据
            this.search();
        },
        methods: {
            getMore() {
                this.upLoadData = [];
                //当前数据大于等于总数据条数停止继续加载
                if (this.upLoadData.length >= this.total) {
                    this.status = 'noMore';
                    this.showMore = true;
                } else {
                    this.status = 'loading'
                    uni.showNavigationBarLoading();
                    this.page++;  //当前页码加1
                    this.request({
                        url: '/getList',
                        method: 'POST',
                        data: {}
                    }).then(res => {
                        uni.hideLoading();
                        if (res.code === 200) {
                            this.showMore = true;
                            //将接口获取的存在待处理数据列表中
                            this.upLoadData = res.data;
                            //计算出总页码数  向上取整
                            let totalPage = Math.ceil(this.total / this.pagesize)
                            //当前页码大于总页码数  停止继续加载
                            if (this.page > totalPage) {
                                this.status = 'noMore'
                                uni.hideNavigationBarLoading()
                            } else {
                                //反之在一秒后将待处理数据添加到数据组中
                                setTimeout(res => {
                                    this.listData = this.listData.concat(this.upLoadData);
                                    this.status = 'more';
                                    uni.hideNavigationBarLoading();
                                }, 1000);
                            }
                        } else {
                            this.showMore = false;
                        }
                    }).catch(error => {
                        console.log("请求失败:", error)
                    })
                }

            },
            search() {
                this.request({
                    url: '/getList',   //接口地址
                    method: 'POST',
                    data: {}   // 请求参数
                }).then(res => {
                    if (res.code === 200) {
                        this.listData = res.data   // 获取初始化数据
                        this.total = res.total // 获取总数据条数
                    }
                })
            },
        }
    }
</script>
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
基于引用和引用的描述,Vueuni-app可以被用来开发疫苗预约小程。疫苗预约小程是基于小程的疫苗预约系统,它通过计算机技术与疫苗管理相结合来实现高效的疫苗管理。此系统可以被划分为管理员和用户两类用户。管理员可以管理用户、疫苗分类、疫苗信息、疫苗预约和系统等功能。用户可以在小程首页上查看疫苗信息、公告信息以及进行个人中心、疫苗预约和我的收藏等操作。 技术栈上,后端可以采用Spring、SpringMVC、Mybatis和Springboot。小程端可以采用uni-app微信开发者工具混合开发模式。至于环境需求,需要微信开发者工具、Java JDK 1.8、IDEA或Eclipse、Tomcat7/Tomcat8/Tomcat9、Windows 7/8/10或Mac OS以及MySQL 5.7或以上版本的数据库。 同时,根据引用的描述,校园疫情防控系统也可以采用Vue和ElementUI来开发PC端,uni-app来开发小程端。这个系统包含了签到记录、离校申请、志愿者申请、核酸疫苗申请、新闻信息、评论信息、年级信息、班级信息、专业信息、隔离人数和用户管理等功能。 综上所述,Vueuni-app可以作为开发疫苗预约小程的技术栈之一,可以帮助开发人员实现高效的疫苗管理和预约功能。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Java基于微信小程序的新冠疫苗预约小程 springboot+vue+elementUI](https://blog.csdn.net/z459382737/article/details/128294937)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [SpringBoot+Vue+ElementUI+uni-app前后端分离Java项目实战校园疫情防控系统](https://blog.csdn.net/qq_45990281/article/details/128317283)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [使用socket.io + Vue + uni-app搭建的完整分离版客服系统源码.zip](https://download.csdn.net/download/weixin_47367099/85328395)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值