首頁  >  問答  >  主體

"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 天前599

全部回覆(1)我來回復

  • P粉151466081

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

    我昨天遇到類似的問題了。 我在routes/web.php中再次渲染時使用了inertia,我認為發生了覆蓋。嘗試在你的路由中不使用inertia,對我有用。

    回覆
    0
  • 取消回覆