uni-app 下拉刷新、 上拉触底(列表信息)、 上滑加载(短视频) 一键搞定

一、下拉刷新

1. 首先找到pages.json中

给需要进行下拉刷新的页面设置可以下拉刷新

2. 然后在需要实现下拉刷新的script标签内添加

导入onPullDownRefresh

复制代码
import {onPullDownRefresh} from '@dcloudio/uni-app'

下拉刷新触发的事件

复制代码
onPullDownRefresh(()=> {
	console.log('正在刷新中......');

	setTimeout(function () {
		uni.stopPullDownRefresh();
	}, 1000);
})

二、上拉触底

1.在需要实现上拉触底的script标签内添加

复制代码
import {onPullDownRefresh} from '@dcloudio/uni-app'

onReachBottom(()=>{
	console.log('触底啦!')
})	

三、上滑加载

一般用于短视频,向上滑动触发时间,跳转到下一个视频

1. 在需要实现上滑加载的组件上加上参数touchstart、touchmove、touchend:

复制代码
<view class="layout"  
	  @touchstart="touchStart"
      @touchmove="touchMove"
      @touchend="touchEnd">

    //短视频
</view>

2. 在需要实现上滑加载的script标签内添加

复制代码
// 定义变量
const isLoading = ref(false); // 标记是否正在加载
const startY = ref(0); // 记录触摸开始的Y坐标
const distanceThreshold = 60; // 设置触发加载的距离阈值

// 模拟加载数据的函数
const loadData = () => {
  if (isLoading.value) return; // 如果正在加载,则不重复触发
  isLoading.value = true;
  console.log('加载更多数据...');
  // 模拟加载过程
  setTimeout(() => {
    isLoading.value = false;
    // 这里可以添加实际加载数据的逻辑,比如调用API获取数据
  }, 1000);
};



// 触摸开始事件
const touchStart = (event) => {
  startY.value = event.touches[0].clientY;
};

// 触摸移动事件
const touchMove = (event) => {
  const moveY = event.touches[0].clientY;
  const distance = startY.value - moveY; // 计算滑动的距离
  // 如果向上滑动并且超过阈值,则触发加载
  if (distance > distanceThreshold) {
    loadData();
  }
};

// 触摸结束事件
const touchEnd = () => {
  startY.value = 0; // 重置开始Y坐标
};
相关推荐
2501_915921434 小时前
iOS App 电耗管理 通过系统电池记录、Xcode Instruments 与克魔(KeyMob)组合使用
android·ios·小程序·https·uni-app·iphone·webview
2501_9159184115 小时前
iOS App 测试方法,Xcode、TestFlight与克魔(KeyMob)等工具组合使用
android·macos·ios·小程序·uni-app·iphone·xcode
2501_9159214316 小时前
iOS 描述文件制作过程,从 Bundle ID、证书、设备到描述文件生成后的验证
android·ios·小程序·https·uni-app·iphone·webview
2501_915909061 天前
如何保护 iOS IPA 文件中资源与文件的安全,图片、JSON重命名
android·ios·小程序·uni-app·json·iphone·webview
2501_915909061 天前
原生与 H5 共存情况下的测试思路,混合开发 App 的实际测试场景
android·ios·小程序·https·uni-app·iphone·webview
游戏开发爱好者82 天前
了解 Xcode 在 iOS 开发中的作用和功能有哪些
android·ios·小程序·https·uni-app·iphone·webview
2501_915106322 天前
iOS 抓包工具实战实践指南,围绕代理抓包、数据流抓包和拦截器等常见工具
android·ios·小程序·https·uni-app·iphone·webview
Jyywww1212 天前
Uniapp+Vue3 移动端顶部安全距离
uni-app
2501_915106322 天前
如何在 iOS 设备上理解和分析 CPU 使用率(windows环境)
android·ios·小程序·https·uni-app·iphone·webview
怀君2 天前
Uniapp——苹果IOS离线打自定义基座教程
ios·uni-app