cossack910 / CRMSystem

Laravel10 + inertia + vue
0 stars 0 forks source link

Inertia::render #2

Open cossack910 opened 12 months ago

cossack910 commented 12 months ago

Pages配下のInertia/Index.vueをレンダリング

第1引数にコンポーネント、第2引数にプロパティを渡す

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Inertia\Inertia;

class InertiaTestController extends Controller
{
    public function index()
    {
        return Inertia::render('Inertia/Index'); 
    }
}
cossack910 commented 12 months ago

idを渡す場合

コントローラ側, 第2引数の配列にidを渡す

public function show($id) {
        return Inertia::render('Inertia/Show', [
            'id' => $id
        ]);
    }

Vue側(Inertia/Show)

Propsで受け取る

<script setup>
defineProps({
    id: String,
});
</script>

<template>
    {{ id }}
</template>