首页 > 解决方案 > Laravel 8 + Inertia 不渲染变量

问题描述

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

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

控制器组件:

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>

标签: javascriptphplaravelvue.jsinertiajs

解决方案


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

服务器端惯性


推荐阅读