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

在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();
  }
})
相关推荐
jerrywus2 分钟前
别再陪 AI 调 iOS 了:用 cmux + baguette,让 Claude 在你的模拟器里"自己动手"
前端·ios·claude
H Journey18 分钟前
网络编程:服务器监听+非阻塞设置
服务器·网络·服务器监听+非阻塞设置
学困昇35 分钟前
彻底搞懂 Linux 基础 IO:文件描述符、重定向、dup2、缓冲区一次讲透!
linux·运维·服务器·开发语言·c++
赋创小助手40 分钟前
PCIe 8.0 要来了:1TB/s 带宽背后,AI 算力服务器正在进入“高速互联时代”
运维·服务器·人工智能
文心快码BaiduComate43 分钟前
Comate Spec模式实践:电商视频自动化生产数据库eDB-MCP服务开发
前端·后端·架构
page_qiu1 小时前
高并发&大数据量&毫秒级响应系统设计方案
java·前端·数据库·高并发·高响应
皮皮大人1 小时前
agent设计系统-大模型意图识别
前端·人工智能
三维搬砖者1 小时前
挑战AI辅助从零构建3D模型编辑器:01基于Vue3 + Three.js的现代化架构设计
前端·vue.js·github
GinoWi1 小时前
Python 集合
前端·python
时光足迹1 小时前
Tiptap之标注组件
前端·javascript·react.js