Heim  >  Fragen und Antworten  >  Hauptteil

„Laravel 8 + Inertia zeigt Variablen nicht korrekt an“

Ich habe tatsächlich Probleme mit der Übergabe von Daten an eine GET-Anforderungsseite. Ich versuche, Daten aus der Datenbank an die Dashboard.vue-Komponente zu übergeben (mit Laravel 8 + Inertia.js-Stack)

Aber es ist nichts passiert, warum?

Controller-Komponente:

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'),
            ]);
}

Frontend:

<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 Tage vor603

Antworte allen(1)Ich werde antworten

  • P粉151466081

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

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

    Antwort
    0
  • StornierenAntwort