uniapp刷新页面
在uniapp中刷新页面可以使用以下方法:
- 使用页面刷新组件
在页面的template中添加以下代码:
<view>
<pull-down-refresh @refresh="onRefresh"></pull-down-refresh>
</view>
在页面的methods中添加以下代码:
onRefresh() {
// 这里写刷新页面的逻辑
}
- 使用下拉刷新事件
在页面的template中添加以下代码:
<view @touchstart="onTouchStart" @touchmove="onTouchMove" @touchend="onTouchEnd">
<!-- 这里是页面内容 -->
</view>
在页面的data中添加以下代码:
data() {
return {
startY: 0,
endY: 0
}
}
在页面的methods中添加以下代码:
onTouchStart(e) {
this.startY = e.touches[0].clientY;
}
onTouchMove(e) {
this.endY = e.touches[0].clientY;
}
onTouchEnd() {
if (this.endY - this.startY > 50) {
// 这里写刷新页面的逻辑
}
}
以上两种方法均可用于刷新页面,具体使用哪种方法取决于个人的需求和习惯
原文地址: https://www.cveoy.top/t/topic/fTzy 著作权归作者所有。请勿转载和采集!