微信小步调分页和下拉刷新

[复制链接]
发表于 2025-9-18 21:22:34 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
在page.json中配置下拉刷新和底部距顶部的间隔: 
  1. {
  2.                                         "path": "school-detail",
  3.                                         "style": {
  4.                                                 "navigationStyle": "custom",
  5.                                                 "navigationBarTextStyle": "black",
  6.                                                 "enablePullDownRefresh": true, //下拉刷新
  7.                                                 "onReachBottomDistance":100  //底部距顶部的距离
  8.                                         }
  9.                                 },
复制代码
如下页面接口,须要分页的页面,在后端接口中都须要page_size(一次加载的数据条数)
  1. //推免信息
  2. export const getExemption = async (id: number,pageSize: number): Promise<exemption> => {
  3.     try {
  4.         const res = await http<exemption>({
  5.             method: 'POST',
  6.             url: '/universityselectionserver/postgraduate-exemption',
  7.             data: {
  8.                 token: memberStore.profile?.token,
  9.                 user_id: memberStore.profile?.user_id,
  10.                 college_code: 10486,
  11.                 last_id: 0,
  12.                 page_size: 10
  13.             }
  14.         });
  15.         return res.data;
  16.     } catch (error) {
  17.         console.error("Failed to fetch major score:", error);
  18.         return {} as exemption;
  19.     }
  20. }
复制代码
 下面是在相应页面的页面刷新和分页的代码
  1. const currentPage_exemption = ref(1);
  2. const pageSize_exemption = ref(10);
  3. const hasMore_exemption = ref(true);
  4. //推免数据的分页加载和下拉刷新
  5. const fetchExemption = async () => {
  6.   if(loading.value) return;
  7.   loading.value = true;
  8.   try {
  9.     const response = await getExemption(currentPage_exemption.value,pageSize_exemption.value);
  10.     console.log('推免数据:', response);
  11.     if(currentPage_exemption.value === 1) {
  12.       exemptionList.value = props.infoList;
  13.     }else {
  14.       exemptionList.value = [...exemptionList.value,...props.infoList];
  15.     }
  16.     hasMore_exemption.value = props.infoList.length >= pageSize_exemption.value;
  17.   }catch (error) {
  18.     console.error('获取推免数据失败', error);
  19.   }finally {
  20.     loading.value = false;
  21.     uni.stopPullDownRefresh();
  22.   
  23.   };
  24. }
  25. onMounted(() => {
  26.   fetchNotice();
  27.   fetchExemption();
  28. });
  29. onPullDownRefresh(() => {
  30.   currentPage.value = 1;
  31.   hasMore.value = true;
  32.   currentPage_exemption.value = 1;
  33.   hasMore_exemption.value = true;
  34.   fetchNotice();
  35.   fetchExemption();
  36. })
  37. onReachBottom(() => {
  38.   if(hasMore.value) {
  39.     currentPage.value++;
  40.     fetchNotice();
  41.    
  42.   }
  43.   if(hasMore_exemption.value) {
  44.     currentPage_exemption.value++;
  45.     fetchExemption();
  46.   }
  47. })
复制代码
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表