首页  >  问答  >  正文

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


P粉317679342P粉317679342349 天前600

全部回复(1)我来回复

  • P粉151466081

    P粉1514660812023-11-06 09:28:14

    我昨天遇到了类似的问题。 我在routes/web.php中再次渲染时使用了inertia,我认为发生了覆盖。尝试在你的路由中不使用inertia,对我有用。

    回复
    0
  • 取消回复