1

我的控制器是这样的:

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

dd($products);像这样的结果: https ://postimg.org/image/w39usbfrv/

我的视图刀片 laravel 是这样的:

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

我的 vue 组件产品列表如下:

<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>

如果我运行代码,结果{{this.page}}为空

如果这个:{{$products->links()}}放置在视图 laravel 中它可以工作

但是如果传给vue组件,结果是空的

我怎么解决这个问题?

笔记 :

我知道如何使用 ajax 请求。但我不使用它。在这里我只想尝试另一种方式

4

1 回答 1

0

您不能以这种方式将其编码为 JSON,请阅读此处有什么帮助:

https://laravel.com/docs/5.6/pagination#converting-results-to-json

于 2018-02-22T08:07:39.187 回答