fix: client-io-component.ts

This commit is contained in:
Michael Brevard 2024-03-24 19:52:16 +02:00 committed by GitHub
parent ae2bb27ac0
commit 6a32dc1c9e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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
};
}
});