Skip to content

Instantly share code, notes, and snippets.

@MartinMalinda
Last active August 8, 2021 10:50
Show Gist options
  • Save MartinMalinda/c47707f2c256ebaf316c78d1bb62bdd8 to your computer and use it in GitHub Desktop.
Save MartinMalinda/c47707f2c256ebaf316c78d1bb62bdd8 to your computer and use it in GitHub Desktop.
<script lang="ts">
import { useIntersectionObserver } from '@vueuse/core'
export default {
setup() {
const shouldRender = ref(false);
const targetEl = ref();
const { stop } = useIntersectionObserver(
targetEl,
([{ isIntersecting }]) => {
if (isIntersecting) {
shouldRender.value = true;
stop();
}
}, {
rootMargin: '600px'
}
);
return { targetEl, shouldRender }
}
}
</script>
<template>
<div ref="targetEl">
<slot v-if="shouldRender" />
</div>
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment