uniapp实现上拉加载更多

article/2025/9/18 1:46:05

目录

一、添加全部

1.在主页面中添加一列

 2.改云函数

3.插件市场导入 加载中组件

二、实现上拉加载

1.云函数中可以接收参数

2.获取下拉事件

3.写触发这个下拉干嘛

在 显示加载中的组件里面


一、添加全部

1.在主页面中添加一列

data.unshift({name:'全部'}) //添加一列 ‘全部’

 

 2.改云函数

(累了 直接上代码)这里match匹配空对象相当于全部哈

'use strict';
const db=uniCloud.database()//1.创建引用
exports.main = async (event, context) => {//event为客户端上传的参数const {name} = event//等同 var name=event.namelet matchObj={}if (name !== '全部') {matchObj = {classify: name}} const list =await db.collection('article')	//2.创建.aggregate()//获取聚合操作实例.match(matchObj)//筛选出classify是前端开发的.project({content:0})//类似.field.end()return {code: 200,msg: '数据请求成功',data: list.data}};

3.插件市场导入 加载中组件

二、实现上拉加载

上拉加载实际上把一页分成好几页来加载,拉一下就加载一点点 就这样

1.云函数中可以接收参数

'use strict';
const db=uniCloud.database()//1.创建引用
exports.main = async (event, context) => {//event为客户端上传的参数const {name,page = 1,pageSize = 10} = event//等同 var name=event.namelet matchObj={}if (name !== '全部') {matchObj = {classify: name}}const list =await db.collection('article')	//2.创建.aggregate()//获取聚合操作实例.match(matchObj)//筛选出classify是前端开发的.project({content:0})//类似.field.skip(pageSize * (page - 1)).limit(pageSize)//返回几条数据?.end()return {code: 200,msg: '数据请求成功',data: list.data}};

2.获取下拉事件

	<scroll-view class="list-scroll" scroll-y @scrolltolower="loadmore">

传呀传

methods:{loadmore(){this.$emit('loadmore')}}

传呀传

传到头啦

3.写触发这个下拉干嘛

loadmore() {if (this.load[this.activeIndex].loading === 'noMore') returnthis.load[this.activeIndex].page++this.getList(this.activeIndex)},

getList里面

getList(current) {if (!this.load[current]) {this.load[current] = {page: 1,loading: 'loading'}} //分离page 不能让他们共享一个console.log('当前的页数', this.load[current].page);this.$api.get_list({ //传三个参数name: this.tab[current].name,page: this.load[current].page,pageSize: this.pageSize}).then(res => {console.log(res);const {data} = resif (data.length === 0) {let oldLoad = {}oldLoad.loading = 'noMore'oldLoad.page = this.load[current].pagethis.$set(this.load, current, oldLoad)// 强制渲染页面this.$forceUpdate()return}let oldList = this.listCatchData[current] || []oldList.push(...data)this.$set(this.listCatchData, current, oldList)})}

完整代码:

<template><swiper @change="change" :current="activeIndex" style="height: 100%"><swiper-item style="height: 100%" v-for="(item ,index) in tab" :key="index" class="swiper-item"><list-item :list="listCatchData[index]" :load="load[index]" @loadmore="loadmore"></list-item></swiper-item></swiper>
</template><script>export default {name: "list",props: {tab: {type: Array,default () {return []}},activeIndex: {type: Number,default: 0}},data() {return {list: [],// js 的限制 listCatchData[index] = datalistCatchData: {},load: {},pageSize: 10};},watch: {tab(newVal) {//如果是新的tabif (newVal.length === 0) returnthis.listCatchData = {}this.load = {}  this.getList(this.activeIndex)}},methods: {loadmore() {//if ‘没有更多数据’就返回 不申请啦if (this.load[this.activeIndex].loading === 'noMore') returnthis.load[this.activeIndex].page++this.getList(this.activeIndex)},change(e) {const {current} = e.detail; //取到 current这个数据this.$emit('change', current)// TODO 当数据不存在 或者 长度是 0 的情况下,才去请求数据 不用每次都加载已经加载过的if (!this.listCatchData[current] || this.listCatchData[current].length === 0) {this.getList(current)}},getList(current) {if (!this.load[current]) {//分离page 不能让他们共享一个this.load[current] = {page: 1,loading: 'loading'}} console.log('当前的页数', this.load[current].page);this.$api.get_list({ //传三个参数name: this.tab[current].name,page: this.load[current].page,pageSize: this.pageSize}).then(res => {console.log(res);const {data} = resif (data.length === 0) //if没有数据就搞它let oldLoad = {}oldLoad.loading = 'noMore'oldLoad.page = this.load[current].pagethis.$set(this.load, current, oldLoad)// 强制渲染页面this.$forceUpdate()return}let oldList = this.listCatchData[current] || []//解决每次加载覆盖 没有新的oldList.push(...data)this.$set(this.listCatchData, current, oldList)})}}}
</script><style lang="scss">.home-swiper {height: 100%;.swiper-item {height: 100%;overflow: hidden;.list-scroll {height: 100%;}}}
</style>

在 显示加载中的组件里面

<uni-load-more  iconType="snow" :status="load.loading"></uni-load-more>


http://chatgpt.dhexx.cn/article/bhhRRWJp.shtml

相关文章

element-ui,实现点击“加载更多“

首先&#xff0c;实现的大概效果如下&#xff1a; 接下来代码如下: <el-dialog v-el-drag-dialog title"预览" :visible.sync"dialogFormPreview" width"500px" ><div v-for"item in logList.slice(0,loadNum)" :key"i…

史上最全的使用RecyclerView实现下拉刷新和上拉加载更多

前言&#xff1a; 纵观多数App&#xff0c;下拉刷新和上拉加载更多是很常见的功能&#xff0c;但是谷歌官方只有一个SwipeRefreshLayout用来下拉刷新&#xff0c;上拉加载更多还要自己做。 本篇文章基于RecyclerView简单封装了这两个操作&#xff0c;下拉刷新支持LinearLayoutM…

一种Flutter加载更多的实现方法

转载注明出处&#xff1a;https://blog.csdn.net/skysukai 1、why flutter&#xff1f; 我们在进行Android开发的时候&#xff0c;比如布局文件&#xff0c;会创建一个xml来存放布局。写熟悉了觉得没什么&#xff0c;可是&#xff0c;用xml来存放布局文件是十年前的技术了。在…

Android BaseRecyclerViewAdapterHelper上拉加载更多

private boolean isErr false; //是否加载错误 private int TOTAL_COUNTER 16; //一共模拟加载16条数据&#xff0c;所有的数据总数 private int mCurrentCounter 6; //当前的数据总数&#xff0c;因为第一次默认加载6个//1.上拉加载mImgDetailsAdapter.setOnLoadMoreListen…

使用SmartRefreshLayout下拉刷新框架实现加载更多

使用 SmartRefreshLayout 可以实现recyclerview的下拉刷新和上拉加载更多&#xff0c;但是有时候在使用上拉加载更多时&#xff0c;不同的json格式需要不同的判断方法 1、后台根据每次相加的totalElements的个数作为请求的参数即pageSize12 pageNo1 {"content":[{…

Android recyclerview上拉加载更多

记录一下视频列表&#xff08;recyclerview&#xff09;上拉显示一个“加载更多”的item&#xff0c;然后加载数据。 效果图&#xff1a; 实现思路&#xff1a; 1.写两个item布局&#xff0c;一个用来展示数据&#xff0c;一个用来展示加载中也就是滑到最下方的时候显示的“…

vue 点击加载更多

然后按照需求一步步来&#xff0c;先写基本页面 如果不想看过程&#xff0c;直接去后面完整代码那就可以 <template><div><div><div class"Journalism" ref"div"><div v-for"item in todos" :key"item.id&quo…

uniapp实现点击加载更多

使用场景 举个栗子&#xff1a;外卖app当订单商品数量比较多时&#xff0c;不方便一次性展示出来。通常会展示一部分&#xff0c;并在页面给出一个查看更多功能。点击后即可自定义展示剩余内容&#xff0c;比如可以每次点击多展示N个内容&#xff0c;或展示所有。 实现效果 实…

RecyclerView系列之加载更多

一、背景 很久很久以前简单封装过一次RecyclerView&#xff0c;后来一直开发TV端&#xff0c;列表的需求花样不是很多&#xff0c;主要是解决TV端各种兼容问题&#xff0c;也没怎么琢磨这个美丽的控件了&#xff0c;现在打算重新整理一下&#xff0c;其实网上已经有很多优秀的开…

js页面中实现加载更多功能

分页-如何实现加载更多功能&#xff0c;目前的在很多网站上使用的加载更多功能中&#xff0c;使用最多的是iscroll.js实现的上拉加载更多、下拉刷新功能。但是iscroll.js本身并没有集成加载更多的功能&#xff0c;需要进行自行扩展。 最简单的就是给一个加载更多的按钮&#xf…

微信小程序之加载更多(分页加载)实例

1.业务需求&#xff1a;列表滚动到底部时&#xff0c;继续往上拉&#xff0c;加载更多内容 2.必传参数&#xff1a; &#xff08;1&#xff09;page: 1 //第几次加载 &#xff08;2&#xff09;limit: 5//每次加载的显示数据条数 &#xff08;3&#xff09;total: null //需要返…

自己收藏整理的一些操作系统资源

在CSDN混迹这么多年 感觉在技术宽度和广度都深不可测的C站 Windows方面的技术相对较少一些 今天&#xff0c;借着寻找C站宝藏的活动 介绍一些C站宝藏的 Windows相关资源技术专栏 附带一下猎奇操作系统的资源~~~ 【操作系统资源&#xff1a;吐血整理&#xff0c;建议收藏&a…

写代码爬取了某 Hub 资源,只为撸这个鉴黄平台!

黄色已经是我们所不容然而却防不胜防的&#xff0c;尤其是对于做内容的工具和平台&#xff0c;所以花了30分钟搭建了一个鉴黄平台&#xff0c;分享给大家。 &#xfeff; 数据准备 &#xfeff; 找了 N 多资源都不能解决问题&#xff0c;于是怒爬某 Bub资料&#xff0c;备用…

QGC(QGroundControl)地面站手把手教你改——高德地图的添加和瓦片地图在线资源

如何添加高德地图和瓦片地图在线资源 1. 演示效果2. 代码添加3. 瓦片地图在线资源3.1 高德地图3.2 天地图3.3 其它地图源相关链接 所有的热爱都要不遗余力&#xff0c;真正喜欢它便给它更高的优先级&#xff0c;和更多的时间吧&#xff01; 关于QGC地面站其它文章请点击这里: …

系统硬件资源测算

上一篇写到了架构在规划时&#xff0c;应该做哪些&#xff1f;当项目启动后&#xff0c;资源的需求就会提上议程&#xff0c;包括人力资源、项目所需的软件资源、硬件资源以及其他资源。而今天想探讨的是很少被触及的硬件资源。因为硬件资源的规划往往都是经验值的积累&#xf…

在线学习Java的资源网站

CodeGym&#xff08;https://codegym.cc/&#xff09;&#xff1a;一个在线Java编程课程&#xff0c;80%的内容是练习&#xff0c;适合一窍不通的入门者。 CodeAcademy&#xff08;https://www.codecademy.com/&#xff09;&#xff1a;该课程注重的是在找工作时非常有用的技术…

RTSP在线视频流资源地址

在线视频流地址&#xff1a; rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov 真机显示界面: 模拟器显示界面: 学好一门语言&#xff0c;动手去练&#xff0c;半天上手&#xff0c;一星期炉火纯青。—— 专攻无人车的学长

在线地图资源

一、ARCGIS在线地图资源 1&#xff0c;全球服务地址目录&#xff1a; http://services.arcgisonline.com/arcgis/rest/services 影像&#xff1a; http://services.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer?fjsapi 电子地图&#xff1a; ht…

【ArcGIS微课1000例】0025:ArcGIS Online当前未连接到在线资源终极解决办法

ArcGIS Online在线资源列表: World Imagery: 底图服务: 中国地图彩色版: 打开ArcGIS时,系统托盘提示“ArcGIS Online当前未连接到在线资源”,如下图所示,如果无法连接到ArcGIS Online,则就无法添加在线资源,如World Imagery等。 关于该问题,网上有多种解决办法,然而…

赶紧收藏3个免费在线资源齐全的网站

非搜 是一个综合搜索网站&#xff0c;能同时获得多个网站上的搜索结果展示&#xff0c;在APP上用户也能自己添加网站&#xff0c;除了看所有影视&#xff0c;还有小说&#xff0c;漫画&#xff0c;招聘&#xff0c;搜索&#xff0c;等搜索类型。 优点&#xff1a;不光包含影视…