优化全局下拉刷新
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<view class="contentStyle" style="">
|
||||
|
||||
<scroll-view class="page" scroll-y :refresher-enabled="true" :refresher-triggered="isRefreshing" @refresherrefresh="onRefresh" @scrolltolower="loadMore">
|
||||
<view class="page">
|
||||
<!-- 空状态 -->
|
||||
<view v-if="houseList.length === 0" class="empty-state">
|
||||
<uni-icons type="info" size="30" color="#ccc"></uni-icons>
|
||||
@@ -46,7 +46,7 @@
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
<!-- 底部添加按钮 -->
|
||||
<view class="bottom-btn">
|
||||
<button class="add-btn" @click="addHouse">添加房屋</button>
|
||||
@@ -62,7 +62,9 @@
|
||||
onMounted,
|
||||
} from 'vue'
|
||||
import {
|
||||
onShow
|
||||
onShow,
|
||||
onPullDownRefresh,
|
||||
onReachBottom
|
||||
} from '@dcloudio/uni-app'
|
||||
import {
|
||||
getMyHouseList,
|
||||
@@ -74,17 +76,15 @@
|
||||
const pageNum = ref(1)
|
||||
const pageSize = ref(10)
|
||||
const noMoreData = ref(false)
|
||||
const isRefreshing = ref(false)
|
||||
|
||||
// ==================== 下拉刷新 ====================
|
||||
const onRefresh = () => {
|
||||
isRefreshing.value = true
|
||||
// ==================== 下拉刷新 ====================
|
||||
onPullDownRefresh(() => {
|
||||
pageNum.value = 1
|
||||
noMoreData.value = false
|
||||
houseList.value = []
|
||||
loading.value = false
|
||||
getList()
|
||||
}
|
||||
})
|
||||
|
||||
// ==================== 获取列表数据 ====================
|
||||
const getList = async () => {
|
||||
@@ -113,8 +113,7 @@
|
||||
console.error('列表接口报错:', err)
|
||||
} finally {
|
||||
loading.value = false
|
||||
isRefreshing.value = false
|
||||
uni.stopPullDownRefresh()
|
||||
uni.stopPullDownRefresh()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,6 +124,11 @@
|
||||
getList()
|
||||
}
|
||||
|
||||
// ==================== 上拉加载更多 ====================
|
||||
onReachBottom(() => {
|
||||
loadMore()
|
||||
})
|
||||
|
||||
// 页面加载时请求第一页
|
||||
onMounted(() => {
|
||||
pageNum.value = 1
|
||||
@@ -211,16 +215,11 @@
|
||||
|
||||
<style scoped>
|
||||
.contentStyle {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100vh;
|
||||
/* 关键:固定高度,底部按钮不动 */
|
||||
min-height: 100vh;
|
||||
background-color: #f5f7fa;
|
||||
}
|
||||
|
||||
.page {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 0px 40rpx 120rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user