<template>
<div style="width:100%;height: 2000px;background-color: aqua;"></div>
时空的距离是开机登陆我看见了乌克兰我看1时空的距离是开机登陆我看见了
乌克兰我看1时空的距离是开机登陆我看见了乌克兰我看1时空的距离是开机登陆我看见了乌克兰我看1时空的距离是开机登陆我看见
了乌克兰我看1时空的距离是开机登陆我看见了乌克兰我看1时空的距离是开机登陆我看见了乌克兰我看1时空的距离是开机登陆我看见了乌克兰我看
1时空的距离是开机登陆我看见了乌克兰我看1时空的距离是开机登陆我看见了乌克兰我看1时空的距离是开机登陆我看见了乌克兰我看1时空的距离是开机登
陆我看见了乌克兰我看1时空的距离是开机登陆我看见了乌克兰我看1时空的距离是开机登陆我看见了乌克兰我看1时空的距离是开机登陆我看见了乌克兰我看1时空的距离
是开机登陆我看见了乌克兰我看
<div style="width:100%;height:500px;background-color: blanchedalmond;"></div>
<div ref="tar">
<UI v-if="visabled" />
</div>
</template>
<script setup lang="ts">
import { ref,defineAsyncComponent,watchEffect,onUnmounted } from 'vue'
import { useIntersectionObserver } from '@vueuse/core';
const UI = defineAsyncComponent(() =>
import('./demo.vue')
)
const tar = ref(null)
const visabled = ref(false)
const {stop} = useIntersectionObserver(
tar,
([{isIntersecting}]) =>{
if(isIntersecting){
console.log(isIntersecting)
visabled.value = isIntersecting
}
}
)
console.log(visabled.value)
watchEffect(() => {
if (visabled.value) {
stop() //当加载过一次就取消监视,以免每次滑动页面重复请求加载
} else {
}
})
onUnmounted(()=>{
stop(); // 停止监控
})
</script>
<style scoped>
.read-the-docs {
color: #888;
}
</style>
VUE3中@vueuse/core包useIntersectionObserver懒加载功能
最新推荐文章于 2024-07-03 09:15:00 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)