Simple Vue.js Pagination Example with Laravel

Simple Vue.js Pagination Example with Laravel

In this post we will give you information about Simple Vue.js Pagination Example with Laravel. Hear we will give you detail about Simple Vue.js Pagination Example with Laravel And how to use it also give you demo for it if it is necessary.

Pagination is a method for dividing content into several pages and creating appropriate layouts for a better and more organized presentation. Pagination is an essential requirement for blogs, websites that wish their front-pages to be sufficiently little to stack but then sufficiently showcase the most important posts. In this case, Laravel pagination or Vue pagination is a perfect choice for developers.

Components are one of the most powerful features of Vue. They help you extend basic HTML elements to encapsulate reusable code. At a high level, components are custom elements that Vue’s compiler attaches behavior to.

In this blog, I am going to describe how we can make pagination components using Laravel and Vue.js. Let’s get started.

At first, download the Fresh Laravel app, Create a database in MySQL and edit the database credentials in the .env file and go up to your project directory using the command line, run the migration files using the command  php artisan migrate.

Now, a database is created and a users table is also created, Let’s run the command  php artisan tinker and  App Models User :: factory (10) -> create ();  this will generate 100 random records for the user’s table, Now we are going to paginate these 100 records of the user’s table.

Now, Create a route inside  routes / api.php

use AppHttpControllersAPIUserController;


In the Above routes, the first one is useful to return the user’s records in JSON format.

Let’s create one UserController  inside the Controllers / API directory and add an index method to return user’s paginated records.


namespace AppHttpControllersAPI;

use AppHttpControllersController;
use IlluminateHttpRequest;
use AppModelsUser;

class UserController extends Controller
    public function index(){
        $users = User::paginate(10);
    	return response()->json($users);

To see the paginated records, just hit the URL http://<url>/api/users?page=1then you can see something like this JSON formatted data.

Also see:  How to Use Bootstrap in Your Vue.js Apps

Now we have to setup npm for our vue js. For more about npm  visit  Vue js

Run Following Command

composer require laravel/ui

Now set Vue.js as our Frontend, For this run following command

php artisa ui vue

Now npm install

npm install

Install laravel-vue-pagination

npm install laravel-vue-pagination


yarn add laravel-vue-pagination

Go to your resources / js / app.js  and paste the following code


window.Vue = require('vue').default;

Vue.component('users', require('./components/Users.vue').default);

const app = new Vue({
    el: '#app',

resources / js / components / Users.vue

    <div >
        <div >
            <div >
                <div >
                    <div >
                        <h3>Simple Vue.js Pagination Example with Laravel - <a href="" target="_blank">onlinecode</a></h3>
                    <div >
                        <div >
                            <table >
                                <tbody v-if="users && > 0">
                                    <tr v-for="(user,index) in" :key="index">
                                        <td>{{ }}</td>
                                        <td>{{ }}</td>
                                        <td>{{ }}</td>
                                <tbody v-else>
                                        <td align="center" colspan="3">No record found.</td>
                        <pagination align="center" :data="users" @pagination-change-page="list"></pagination>

    import pagination from 'laravel-vue-pagination'
    export default {
            return {
            async list(page=1){
                await axios.get('/api/users?page=${page}').then(({data})=>{
                    this.users = data
                }).catch(({ response })=>{

<style scoped>
        margin-bottom: 0;

In the last step, we will update our welcome.blade.php file. in this file, we will use the app.js file and use it, so let’s update.

resources / views / welcome.blade.php

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Simple Vue.js Pagination Example with Laravel - onlinecode</title>
        <link rel="stylesheet" type="text/css" href="{{ mix('css/app.css') }}">
        <div id="app">
        <script type="text/javascript" src="{{ mix('js/app.js') }}"></script>

Now you have to run the below command to update the app.js file:

npm run dev

It’d be a good idea to follow along with the simple demo app that can be found in  this GitHub repo .

Also see:  Laravel Livewire Crud Tutorial

If you have any queries or doubts about this topic please feel free to  contact us . We will try to reach you.


Hope this code and post will helped you for implement Simple Vue.js Pagination Example with Laravel. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US