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

在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();
  }
})
相关推荐
上海云盾-小余1 分钟前
Web 业务常见 SQL 注入攻击原理详解及 WAF 防护部署实战教程
前端·数据库·sql
zs宝来了2 分钟前
Next.js SSR/SSG:路由与渲染模式深度解析
前端·javascript·框架
ZC跨境爬虫5 分钟前
UI前端美化技能提升日志day5:从布局优化到CSS继承原理深度解析
前端·css·ui·html·状态模式
易生一世8 分钟前
Kiro CLI的context详解
前端
huangql52011 分钟前
CSS布局(六):Grid —— 像围棋一样布局
前端·css
Mr数据杨13 分钟前
AIGC工具平台-Tarui2.x智能工具桌面错误解决办法
运维·服务器·aigc
谢尔登14 分钟前
【Next】客户端组件和服务端组件
前端·javascript·react.js·架构
Mintopia14 分钟前
合合信息蜜蜂 AI 最新资讯(2026.4.22 官方发布)
前端
Mintopia14 分钟前
如何用第一性原理提升问题解决能力
前端