Vue Intersect is a Vue 2 component designed to wrap the native Intersection Observer API, providing a declarative way to detect when an HTML element enters or leaves the viewport. Last published in March 2020 (version 1.1.6), this package is specifically compatible with Vue 2.x projects and has not been updated for Vue 3. Modern Vue 3 applications typically implement similar functionality using composables (e.g., `@intersection-observer/vue`) or directives, which align better with the Composition API. Due to its sole reliance on Vue 2 and lack of recent development, it is considered abandoned for new projects, though it remains functional for existing Vue 2 applications. Its primary differentiation was simplifying a browser API within the Vue 2 ecosystem.
npm install vue-intersectVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates global registration of the `Intersect` component and its usage with `change`, `enter`, and `leave` events. It shows how to track visibility and trigger actions when an element scrolls into or out of view, with a custom threshold.
For Vue 3 projects, consider using a modern Vue 3-compatible Intersection Observer composable or directive like `@intersection-observer/vue` which uses the Composition API.
If supporting older browsers, integrate a suitable polyfill for the Intersection Observer API (e.g., `intersection-observer` polyfill from WICG) into your build process.
Always include `0` in your `threshold` array if you intend to capture the exact moment an element completely leaves the viewport, e.g., `:threshold="[0, 0.5, 1]"`.
Globally register the component using `Vue.component('Intersect', VueIntersect);` or locally import it: `import Intersect from 'vue-intersect'; export default { components: { Intersect }, ... };`Ensure that you defensively check `if (entry && entry.isIntersecting !== undefined)` within your callback. For issues with `v-if`, ensure the observer instance is correctly managed or consider alternative patterns, as `vue-intersect` can have subtle interactions with conditional rendering.