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