moses's avatar
Level 2

How can I display pagination laravel on the vue component?

My controller like this :

public function index()
{
    $products = $this->product->list(); 
    dd($products);
    return view('admin.product.index',compact('products'));
}

The result of dd($products); like this : https://postimg.org/image/w39usbfrv/

My view blade laravel like this :

<section class="content">
    <product-list :product-data="{{json_encode($products)}}" :page="{{json_encode($products->links())}}"></product-list>
</section>

My vue component product list like this :

<template>
    <div class="box">
        ...
            <table class="table table-list">
                ...
                <tr v-for="item in products" :key="item.id">
                    <td>{{item.name}}</td>
                    <td>{{item.createdAt}}</td>
                    <td>{{item.updatedAt}}</td>
                </tr>
                ...
            </table>
            <div class="box-footer">
                ...
                    {{this.page}}
                ...
            </div>
        ...
    </div>
</template>
<script>
    export default {
        props: ['productData','page'],
        data(){
            return {
                ...
                products: this.productData.data,
            }
        },
        ...
    }
</script>

If I run the code, the result of {{this.page}} is empty

If this : {{$products->links()}} placed in view laravel it works

But if it passed on the vue component, the result is empty

How can I solve this problem?

Note :

I know how to use ajax request. But I don't use it. Here I just want to try the another way

0 likes
1 reply

Please or to participate in this conversation.