mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-31 15:50:32 +00:00
fix: client-io-component.ts
This commit is contained in:
parent
ae2bb27ac0
commit
6a32dc1c9e
@ -1,26 +1,32 @@
|
||||
import { defineComponent, ref } from "vue"
|
||||
import { ref, onMounted, onUnmounted, defineComponent } from 'vue';
|
||||
|
||||
export default defineComponent({
|
||||
emits: ['intersected'],
|
||||
setup() {
|
||||
const data = ref(null);
|
||||
const isIntersecting = ref(false);
|
||||
const target = ref(null);
|
||||
let observer: Ref<IntersectionObserver | null> = ref(null)
|
||||
onMounted(() => {
|
||||
const observer = new IntersectionObserver(entries => {
|
||||
entries.forEach(entry => {
|
||||
if (entry.isIntersecting) {
|
||||
isIntersecting.value = true;
|
||||
emit('intersected');
|
||||
observer.unobserve(target.value);
|
||||
}
|
||||
});
|
||||
setup(props, { emit }) {
|
||||
const intersectionTarget = ref(null);
|
||||
let observer = null;
|
||||
|
||||
const intersectionCallback = (entries) => {
|
||||
entries.forEach(entry => {
|
||||
if (entry.isIntersecting) {
|
||||
emit('intersect');
|
||||
observer.unobserve(entry.target);
|
||||
}
|
||||
});
|
||||
observer.observe(target.value);
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
observer = new IntersectionObserver(intersectionCallback);
|
||||
observer.observe(intersectionTarget.value);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
if (observer) {
|
||||
observer.disconnect();
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
isIntersecting
|
||||
intersectionTarget
|
||||
};
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user