简体   繁体   English

Laravel 8 + 惯性不渲染变量

[英]Laravel 8 + Inertia is not rendering variables

I actually struggling with passing data into GET request page where I trying to pass data from database to Dashboard.vue component (Using Laravel 8 + Inertia.js stack)我实际上正在努力将数据传递到 GET 请求页面,我试图将数据从数据库传递到 Dashboard.vue 组件(使用 Laravel 8 + Inertia.js 堆栈)

But nothing happened, why?但是什么都没发生,为什么?

Controller component: Controller 组件:

public function index(Request $request)
{
        return Inertia::render('Dashboard', [
            'percentages' => $percentages = DB::table('profits')->where('user_id', $request->user()->id)->sum('percentage'),
            'profits' => $profits = DB::table('profits')->where('user_id', $request->user()->id)->sum('total_profit'),
            ]);
}

Front-end:前端:

    <div class="container">
                    <div class="row">
                        <div class="col-sm-5 text-center fund-profits">
                          {{profits}}
                        </div>
                        <div class="col-sm-2 text-center nomad-separator">
                            |
                        </div>
                        <div class="col-sm-5 text-center fund-profits">
                          {{percentages}}
                        </div>
                    </div>
   </div>
    
        <script>
            import JetApplicationLogo from './../Jetstream/ApplicationLogo'
        
            export default {
                props: ['percentages', 'profits'],
                components: {
                    JetApplicationLogo,
                },      
            }
        </script>

I had a similar problem yesterday.我昨天遇到了类似的问题。 I was rendering again in routes/web.php via inertia, and I believe there was a overwriting.我通过惯性在routes/web.php中再次渲染,我相信有覆盖。 Try without using inertia in your routes, worked for me.尝试在您的路线中不使用惯性,为我工作。

Route::get('/your_route', [YourController::class, 'index']) Route::get('/your_route', [YourController::class, 'index'])

creator of Inertia.js here. Inertia.js 的创建者在这里。

I don't see any issue with what you're doing here, assuming that the Vue component you're showing is in fact the Dashboard.vue page component.假设您显示的 Vue 组件实际上是Dashboard.vue页面组件,我认为您在这里所做的没有任何问题。

What I'd recommend is using the Vue devtools to inspect the props that being received, to make sure they are coming from the server properly.我建议使用Vue devtools来检查收到的道具,以确保它们正确来自服务器。

in my case the route middleware for inertial was not applied so i applied route middleware inertia and it started working again在我的情况下,没有应用惯性的路由中间件,所以我应用了路由中间件惯性,它又开始工作了

server side ineertiajs服务器端惯性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM