|
|
@@ -17,7 +17,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
-import { shallowRef, computed } from 'vue'
|
|
|
+import { shallowRef, computed, nextTick } from 'vue'
|
|
|
import { List, PullRefresh } from 'vant'
|
|
|
|
|
|
const props = defineProps({
|
|
|
@@ -59,34 +59,38 @@ const showError = computed({
|
|
|
set: (val) => emit('update:error', val)
|
|
|
})
|
|
|
|
|
|
+const currentPage = computed({
|
|
|
+ get: () => props.pageIndex,
|
|
|
+ set: (val) => emit('update:pageIndex', val)
|
|
|
+})
|
|
|
+
|
|
|
// 上拉加载
|
|
|
const onLoad = () => {
|
|
|
- let pageIndex = props.pageIndex
|
|
|
- if (refreshing.value) {
|
|
|
- pageIndex = 1
|
|
|
- emit('update:pageIndex', pageIndex)
|
|
|
- }
|
|
|
-
|
|
|
const callback = () => {
|
|
|
- if (refreshing.value) {
|
|
|
+ if (refreshing.value || currentPage.value === 1) {
|
|
|
dataList.value = []
|
|
|
refreshing.value = false
|
|
|
}
|
|
|
if (!showError.value) {
|
|
|
- pageIndex++
|
|
|
+ currentPage.value++
|
|
|
dataList.value.push(...props.updateList)
|
|
|
- emit('update:pageIndex', pageIndex)
|
|
|
emit('updated', dataList.value)
|
|
|
}
|
|
|
loading.value = false
|
|
|
}
|
|
|
|
|
|
- if (pageIndex <= props.pageCount) {
|
|
|
- emit('refresh', callback)
|
|
|
- } else {
|
|
|
- refreshing.value = false
|
|
|
- finished.value = true
|
|
|
+ if (refreshing.value) {
|
|
|
+ currentPage.value = 1
|
|
|
}
|
|
|
+
|
|
|
+ nextTick(() => {
|
|
|
+ if (currentPage.value <= props.pageCount) {
|
|
|
+ emit('refresh', callback)
|
|
|
+ } else {
|
|
|
+ refreshing.value = false
|
|
|
+ finished.value = true
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
// 下拉刷新
|