Browse Source

热门推荐滑动分页

template
liruiqiang 2 months ago
parent
commit
2251e22f42
  1. 40
      src/pages/hot/hot.vue

40
src/pages/hot/hot.vue

@ -20,6 +20,7 @@
v-for="(item, index) in subTypes"
:key="item.id"
v-show="activeIndex === index"
@scrolltolower="onScrolltolower"
scroll-y
class="scroll-view"
>
@ -38,7 +39,9 @@
</view>
</navigator>
</view>
<view class="loading-text">正在加载...</view>
<view class="loading-text">
{{ item.finish ? '没有更多数据了~' : '正在加载...' }}
</view>
</scroll-view>
</view>
</template>
@ -72,14 +75,18 @@ uni.setNavigationBarTitle({ title: currUrlMap!.title })
const bannerPicture = ref('')
//
const subTypes = ref<SubTypeItem[]>([])
const subTypes = ref<(SubTypeItem & { finish?: boolean })[]>([])
//
const activeIndex = ref(0)
//
const getHotRecommendData = async () => {
const res = await getHotRecommendAPI(currUrlMap!.url)
const res = await getHotRecommendAPI(currUrlMap!.url, {
// 便
page: import.meta.env.DEV ? 30 : 1,
pageSize: 10,
})
bannerPicture.value = res.result.bannerPicture
subTypes.value = res.result.subTypes
}
@ -88,6 +95,33 @@ const getHotRecommendData = async () => {
onLoad(() => {
getHotRecommendData()
})
//
const onScrolltolower = async () => {
//
const currsubTypes = subTypes.value[activeIndex.value]
//
if (currsubTypes.goodsItems.page < currsubTypes.goodsItems.pages) {
//
currsubTypes.goodsItems.page++
} else {
//
currsubTypes.finish = true
// 退
return uni.showToast({ icon: 'none', title: '没有更多数据了~' })
}
// API
const res = await getHotRecommendAPI(currUrlMap!.url, {
subType: currsubTypes.id,
page: currsubTypes.goodsItems.page,
pageSize: currsubTypes.goodsItems.pageSize,
})
//
const newsubTypes = res.result.subTypes[activeIndex.value]
//
currsubTypes.goodsItems.items.push(...newsubTypes.goodsItems.items)
}
</script>
<style lang="scss">

Loading…
Cancel
Save