下载:npm i @vueuse/core
使用
<div ref="target"> <NewGoodCourse v-if='targetIsVisible'></NewGoodCourse> </div>
import { useIntersectionObserver } from '@vueuse/core'
const NewGoodCourse = defineAsyncComponent(() => import('../components/home/NewGoodCourse.vue') ) const target = ref(null); const targetIsVisible = ref(false); const { stop } = useIntersectionObserver( target, ([{ isIntersecting }]) => { if( isIntersecting ) { targetIsVisible.value = isIntersecting } }, )