Member-only story

Vue3 Development Solutions()

Shawn Kang
14 min readFeb 5, 2024

--

Vue series of articles

Previous:Vue3 Development Solutions(Ⅰ)

10. Long list loading component

Mainly by monitoring whether the bottom DOM appears in the visible area, and then making data requests to handle some special situations. Usevue’s useIntersectionObserver api is used, which simply encapsulates the IntersectionObserver api, allowing us to more easily implement cross-monitoring of the visible area.

It mainly provides isLoading to display and load more dynamic icons, isFinished to determine whether the data request is completed, and load to request data props for the event.

<script setup>
import { useVModel, useIntersectionObserver } from '@vueuse/core'
import { onUnmounted, ref, watch } from 'vue'

const props = defineProps({
isLoading: {
type: Boolean,
default: false
},
isFinished: {
type: Boolean,
default: false
}
})

// Define loading binding event, load more event
const emits = defineEmits(['update:isLoading', 'load'])

const loading = useVModel(props, 'isLoading', emits)
// Load more
const loadingRef = ref(null)
//…

--

--

Shawn Kang
Shawn Kang

Written by Shawn Kang

Focusing on front-end development and internet writing. Sharing technical tutorials and original fiction. https://skstory.online/

No responses yet

Write a response