小程序-滚动触底-页面列表数据无限加载

// index/index.vue

<template>

<!-- 自定义导航栏 -->

<CustomNavbar />

<scroll-view @scrolltolower="onScrolltolower" scroll-y class="scroll-view">

<!-- 猜你喜欢 -->

<Guess ref="guessRef" />

</scroll-view>

</template>

<script>

// 滚动触底事件

const guessRef = ref<GuessInstance>()

const onScrolltolower = () => {

console.log('滚动到底部啦-guessRef', guessRef.value)

guessRef.value?.getMore()

}

</script>

// src/index/components/guess.vue

<script setup lang="ts">

import { getHomeGoodsGuessLikeAPI } from '@/services/home'

import type { PageParams } from '@/types/global'

import type { GuessItem } from '@/types/home'

import { onMounted, ref } from 'vue'

// 分页参数

const pageParams: Required<PageParams> = {

page: 1,

pageSize: 10,

}

// 猜你喜欢的列表

const guessList = ref<GuessItem\[\]>(\[\])

// 已结束标记

const finish = ref(false)

// 获取猜你喜欢数据

const getHomeGoodsGuessLikeData = async () => {

// 退出分页判断

if (finish.value === true) {

return uni.showToast({ icon: 'none', title: '没有更多数据~' })

}

const res = await getHomeGoodsGuessLikeAPI(pageParams)

// 数组追加

guessList.value.push(...res.result.items)

// 分页条件

if (pageParams.page < res.result.pages) {

// 页码累加

pageParams.page++

} else {

finish.value = true

}

}

// 组件挂载完毕

onMounted(() => {

getHomeGoodsGuessLikeData()

})

// 暴露方法

defineExpose({

getMore: getHomeGoodsGuessLikeData,

})

</script>

<template>

<!-- 猜你喜欢 -->

<view class="caption">

<text class="text">猜你喜欢</text>

</view>

<view class="guess">

<navigator

class="guess-item"

v-for="item in guessList"

:key="item.id"

:url="`/pages/goods/goods`"

>

<image class="image" mode="aspectFill" :src="item.picture"></image>

<view class="name"> {{ item.name }} </view>

<view class="price">

<text class="small">¥</text>

<text>{{ item.price }}</text>

</view>

</navigator>

</view>

<view class="loading-text">

{{ finish ? '亲,我也是有底线的哦~' : '正在加载...' }}

</view>

</template>

效果图:看浏览器 network 面板的接口调用情况

滚动到底部,无数据

相关推荐
高级程序源6 小时前
django校园寻物通失物招领平台32261-计算机课程设计、毕业设计
vue.js·python·mysql·小程序·django·flask·课程设计
高级程序源15 小时前
SSM仓储管理系统31582-计算机课程设计、毕业设计
vue.js·python·mysql·小程序·flask·课程设计
青企通15 小时前
弱网环境下小程序首屏性能优化:从 5.2 秒到 1.4 秒的完整实践
性能优化·小程序
高级程序源17 小时前
springboot本地生活服务平台33399-计算机课程设计、毕业设计
vue.js·spring boot·python·mysql·小程序·flask·课程设计
高级程序源18 小时前
django房屋租赁系统28636-计算机课程设计、毕业设计
python·mysql·elasticsearch·小程序·django·flask·课程设计
CRMEB定制开发18 小时前
开源模型正在吃掉闭源的市场,这意味着什么?
小程序·公众号商城·商城源码·crmeb·开源商城
andrsted1 天前
练题簿在线免费刷题:选择、填空、简答与排序,多种题型练出不同的掌握程度
学习·微信小程序·小程序·学习方法·刷题
长沙三为智能科技1 天前
家政小程序门店运营模块设计:会员、下单、派单、结算四段链路的落地拆解
python·小程序·内容运营
weixin_177297220691 天前
回收小程序做自营还是撮合?先看你手里有什么
小程序
andrsted1 天前
练题簿在线免费刷题:Word、PDF 导题与预览补全,把现成资料变成可练习题库
微信小程序·小程序·pdf·word·学习方法·刷题