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

在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();
  }
})
相关推荐
YYsuni2 分钟前
Google Translate 导致的 React 页面崩溃
前端
会一丢丢蝶泳的咻狗2 分钟前
uni-app安卓端强制更新apk包
android·前端·uni-app
逝水如流年轻往返染尘3 分钟前
CSS基础学习1
前端·css·学习
Hilaku4 分钟前
我踩爆了 CSS Module 的所有坑,别再被骗了
前端·css·react.js
北城笑笑6 分钟前
Server 11 ,⭐通过脚本在全新 Ubuntu 系统中安装 Nginx 环境,安装到指定目录( 脚本安装Nginx )
linux·运维·前端·nginx·ubuntu
小赵学鸿蒙8 分钟前
如何使用第三方库中的@pura/harmony-utils(V1.3.3)申请授权工具类一
前端
断竿散人9 分钟前
CSS选择器与伪类:精准定位元素的终极指南!
前端
憨憨是条狗9 分钟前
在 Vue + Vant + ArcGIS 环境中设置 GraphicsLayer 的标题
前端
onebyte8bits10 分钟前
打造丝滑滚动体验:Scroll-driven Animations 正式上线!
前端·javascript·css·html·html5
三脚猫的喵10 分钟前
微信小程序使用图片实现红包雨功能
javascript·微信小程序