Vue Ads Pagination Component

2.1.7 · active · verified Sun Apr 19

vue-ads-pagination is a Vue.js component designed to provide comprehensive pagination functionality for displaying large lists of items efficiently. It allows users to navigate through pages, showing information about the current item range (e.g., 'Items 1 to 10 of 100') and offering buttons for first, last, next, previous, and specific page selection. The current stable version, 2.1.7, is focused on Vue 2 compatibility. This package distinguishes itself by offering extensive customizability through slots, allowing developers to completely override default components (like the page buttons or item range display) with their own Vue components or apply custom styles to the default elements, making it highly adaptable to various UI designs. It provides distinct events for `page-change` and `range-change` to manage state updates effectively in the parent component. There's no explicit release cadence mentioned, but it acts as a mature, single-purpose component.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to integrate `VueAdsPagination` and `VueAdsPageButton` into a Vue component. It shows binding properties like `total-items`, `page`, and handling `page-change` and `range-change` events. The example also illustrates how to customize the display of item range information and individual pagination buttons using scoped slots.

<template>
    <div id="app">
        <vue-ads-pagination
            :total-items="200"
            :max-visible-pages="5"
            :page="currentPage"
            :loading="loading"
            @page-change="pageChange"
            @range-change="rangeChange"
        >
            <template slot-scope="props">
                <div class="vue-ads-pr-2 vue-ads-leading-loose">
                    Items {{ props.start }} to {{ props.end }} of {{ props.total }}
                </div>
            </template>
            <template
                slot="buttons"
                slot-scope="props"
            >
                <vue-ads-page-button
                    v-for="(button, key) in props.buttons"
                    :key="key"
                    v-bind="button"
                    @page-change="currentPage = button.page"
                />
            </template>
        </vue-ads-pagination>
        <p>Current Page: {{ currentPage + 1 }}</p>
    </div>
</template>

<script lang="ts">
import Vue from 'vue';
import '../node_modules/@fortawesome/fontawesome-free/css/all.css'; // For default button icons
import 'vue-ads-pagination/dist/vue-ads-pagination.css'; // For default styling

import VueAdsPagination, { VueAdsPageButton } from 'vue-ads-pagination';

export default Vue.extend({
    name: 'App',
    
    components: {
        VueAdsPagination,
        VueAdsPageButton,
    },

    data () {
        return {
            loading: false,
            currentPage: 4, // 0-based, so 5th page
        };
    },

    methods: {
        pageChange (page: number) {
            this.currentPage = page; // Update the bound prop
            console.log('Page changed to:', page + 1);
        },
        
        rangeChange (start: number, end: number) {
            console.log('Displaying items from', start + 1, 'to', end + 1);
        },
    },
});
</script>

view raw JSON →