
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
vue-3-infinite-scroll-directive-plugin
Advanced tools
Vue 3 plugin to help implementing an infinite scroll
A Vue 3 directive for implementing infinite scroll functionality.
Test the directive by yourself in this sandbox
npm install npm i vue-3-infinite-scroll-directive-plugin
yarn add npm i vue-3-infinite-scroll-directive-plugin
Import and Register the Plugin In your main application file (e.g., main.ts or main.js), import and register the plugin:
import { createApp } from 'vue';
import App from './App.vue';
import { infiniteScrollPlugin } from 'vue-3-infinite-scroll-directive-plugin';
createApp(App).use(infiniteScrollPlugin).mount('#app');
Add the v-infinite-scroll directive to the scrollable element in your template. Specify the handler function to be called when the bottom of the element is reached.
<template>
<div v-infinite-scroll="handleInfiniteScroll"
data-infinite-scroll-margin="20"
data-infinite-scroll-delay="200"
:data-infinite-scroll-disabled="isLoading">
<!-- Your content here -->
</div>
<div class="loader-wrapper" v-if="isLoading">
<span class="loader"></span>
</div>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
const todos = ref([]);
const nextPage = ref(1);
const isLoading = ref(false);
const handleInfiniteScroll = async () => {
isLoading.value = true;
const data = await (await fetch(`https://jsonplaceholder.typicode.com/todos/${nextPage.value}`)).json();
todos.value.push(data);
nextPage.value++;
setTimeout(() => {
isLoading.value = false;
}, Math.random() * 2000);
};
</script>
<template>
<div v-infinite-scroll="handleInfiniteScroll"
data-infinite-scroll-margin="20"
data-infinite-scroll-delay="200"
:data-infinite-scroll-disabled="isLoading"
>
<ul>
<li v-for="todo in todos" :key="todo.id" class="todo">
<div>
{{ todo.title }}
</div>
</li>
</ul>
</div>
<div class="loader-wrapper" v-if="isLoading">
<span class="loader"></span>
</div>
</template>
v-infinite-scroll: Pass the callback to execute when bottom is reached
data-infinite-scroll-margin: Set the margin (in pixels) from the bottom of the scrollable element to trigger the infinite scroll. Default is 0.
data-infinite-scroll-delay: Set the delay (in milliseconds) before allowing another infinite scroll trigger. Default is 2000.
data-infinite-scroll-disabled: Bind this attribute to a variable to enable/disable infinite scroll based on its truthiness.
export type ScrollableHtmlElement = HTMLElement & { __v_destroyInfiniteScrollObserver?: Function };
The plugin takes care of disconnecting the observer and removing the event listener when the component is destroyed.
This project is licensed under the MIT License - see the LICENSE file for details.
FAQs
Vue 3 plugin to help implementing an infinite scroll
We found that vue-3-infinite-scroll-directive-plugin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.