微信小程序分页和下拉刷新

在page.json中配置下拉刷新和底部距顶部的距离:

复制代码
{
					"path": "school-detail",
					"style": {
						"navigationStyle": "custom",
						"navigationBarTextStyle": "black",
						"enablePullDownRefresh": true, //下拉刷新
						"onReachBottomDistance":100  //底部距顶部的距离
					}
				},

如下页面接口,需要分页的页面,在后端接口中都需要page_size(一次加载的数据条数)

复制代码
//推免信息
export const getExemption = async (id: number,pageSize: number): Promise<exemption> => {
    try {
        const res = await http<exemption>({
            method: 'POST',
            url: '/universityselectionserver/postgraduate-exemption',
            data: {
                token: memberStore.profile?.token,
                user_id: memberStore.profile?.user_id,
                college_code: 10486,
                last_id: 0,
                page_size: 10
            }
        });
        return res.data;
    } catch (error) {
        console.error("Failed to fetch major score:", error);
        return {} as exemption;
    }
}

下面是在相应页面的页面刷新和分页的代码

复制代码
const currentPage_exemption = ref(1);
const pageSize_exemption = ref(10);
const hasMore_exemption = ref(true);
//推免数据的分页加载和下拉刷新
const fetchExemption = async () => {
  if(loading.value) return;
  loading.value = true;
  try {
    const response = await getExemption(currentPage_exemption.value,pageSize_exemption.value);
    console.log('推免数据:', response);
    if(currentPage_exemption.value === 1) {
      exemptionList.value = props.infoList;
    }else {
      exemptionList.value = [...exemptionList.value,...props.infoList];
    }
    hasMore_exemption.value = props.infoList.length >= pageSize_exemption.value;
  }catch (error) {
    console.error('获取推免数据失败', error);
  }finally {
    loading.value = false;
    uni.stopPullDownRefresh();
  
  };
}
onMounted(() => {
  fetchNotice();
  fetchExemption();
});
onPullDownRefresh(() => {
  currentPage.value = 1;
  hasMore.value = true;
  currentPage_exemption.value = 1;
  hasMore_exemption.value = true;
  fetchNotice();
  fetchExemption();
})
onReachBottom(() => {
  if(hasMore.value) {
    currentPage.value++;
    fetchNotice();
    
  }
  if(hasMore_exemption.value) {
    currentPage_exemption.value++;
    fetchExemption();
  }
})
相关推荐
liuyouzhang1 小时前
将基于Archery的web数据库审计查询平台封装为jdbc接口的可行性研究(基于AI)
前端·数据库
码事漫谈7 小时前
大模型输出的“隐性结构塌缩”问题及对策
前端·后端
这儿有一堆花7 小时前
前端三件套真的落后了吗?揭开现代 Web 开发的底层逻辑
前端·javascript·css·html5
郝亚军7 小时前
ubuntu通过samba,让win11可以访问其共享文件夹
linux·服务器·ubuntu
农村小镇哥8 小时前
nginx服务器的介绍
运维·服务器·nginx
.Cnn8 小时前
JavaScript 前端基础笔记(网页交互核心)
前端·javascript·笔记·交互
小夏子_riotous8 小时前
Docker学习路径——3、常用命令
linux·运维·服务器·学习·docker·容器·centos
醉酒的李白、8 小时前
Vue3 组件通信本质:Props 下发,Emits 回传
前端·javascript·vue.js
anOnion8 小时前
构建无障碍组件之Window Splitter Pattern
前端·html·交互设计
NotFound4868 小时前
实战分享Python爬虫,如何实现高效解析 Web of Science 文献数据并导出 CSV
前端·爬虫·python