繁体   English   中英

Laravel 8 + 惯性不渲染变量

[英]Laravel 8 + Inertia is not rendering variables

我实际上正在努力将数据传递到 GET 请求页面,我试图将数据从数据库传递到 Dashboard.vue 组件(使用 Laravel 8 + Inertia.js 堆栈)

但是什么都没发生,为什么?

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'),
            ]);
}

前端:

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

我昨天遇到了类似的问题。 我通过惯性在routes/web.php中再次渲染,我相信有覆盖。 尝试在您的路线中不使用惯性,为我工作。

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

Inertia.js 的创建者在这里。

假设您显示的 Vue 组件实际上是Dashboard.vue页面组件,我认为您在这里所做的没有任何问题。

我建议使用Vue devtools来检查收到的道具,以确保它们正确来自服务器。

在我的情况下,没有应用惯性的路由中间件,所以我应用了路由中间件惯性,它又开始工作了

服务器端惯性

暂无
暂无

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

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