1.1.4 • Published 3 years ago

v-simple-infinite-scroll v1.1.4

Weekly downloads
-
License
-
Repository
-
Last release
3 years ago

V Simple Infinite Scroll

A simple infinite scroll for your Vue3 projects.

Installation

NPM

npm install v-simple-infinite-scroll

Direct include

You can use the CDN: https://unpkg.com/v-simple-infinite-scroll

<script src="https://unpkg.com/v-simple-infinite-scroll@1.0.0/dist/v-simple-infinite-scroll.min.js"></script>

Usage

Here is an example of your component that will contain your list.

The method appointed as the value of @cargar will be executed when the bottom of the element reaches the bottom of the viewport.

<template>
    <v-simple-infinite-scroll
        @cargar="cargar"
        :distance="0"
        style="background-color:red">
        <ul>
            <li v-for="item in list" v-bind:key="item">
                {{item}}
            </li>
        </ul>
    </v-simple-infinite-scroll>
</template>

<script>
import VSimpleInfiniteScroll from '@/v-simple-infinite-scroll.vue';
export default {
    components: {
        VSimpleInfiniteScroll,
    },
    data(){
        return {
            list: []
        };
    },
    methods:{
        cargar(scroll){
            this.requestDataFromServer()
            .then(response=>{
                this.list = this.list.concat(response);
                if(this.list.length < 50){
                    scroll.loaded();
                }else{
                    scroll.complete();
                }
            });
            
        },
        async requestDataFromServer(){
            let arrayTemp = new Array();
            for(let i = 0; i < 5 ; i++){
                arrayTemp.push(Math.trunc(Math.random() * 1000));
            }
            await new Promise(resolve => setTimeout(resolve, 1000)); // 3 sec
            return arrayTemp;
        }
    }

}
</script>

Options

OptionDescription
load-to-fillBoolean(default = true) - indicates if the infinite scroll must load items again until window is full.
distanceNumber(default = 100) - Distance (px) between de bottom of the container and the bottom of the window.

Authors

@mxlauc

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago