【问题标题】:Laravel 8 + Inertia is not rendering variablesLaravel 8 + Inertia 不渲染变量
【发布时间】:2021-03-09 16:57:49
【问题描述】:

我实际上正在努力将数据传递到 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>

【问题讨论】:

    标签: javascript php laravel vue.js inertiajs


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      这里是 Inertia.js 的创建者。

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

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

      【讨论】:

        【解决方案3】:

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

        server side ineertiajs

        【讨论】:

          猜你喜欢
          • 2021-01-26
          • 2021-06-20
          • 2023-02-03
          • 2012-12-15
          • 2022-07-29
          • 1970-01-01
          • 2015-09-15
          • 2019-07-24
          • 2023-02-03
          相关资源
          最近更新 更多