first commit
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
## Inertia v1 + Vue Forms
|
||||
|
||||
- For form handling in Inertia pages, use `router.post` and related methods. Do not use regular forms.
|
||||
@verbatim
|
||||
<code-snippet name="Inertia Vue Form Example" lang="vue">
|
||||
<script setup>
|
||||
import { reactive } from 'vue'
|
||||
import { router } from '@inertiajs/vue3'
|
||||
import { usePage } from '@inertiajs/vue3'
|
||||
|
||||
const page = usePage()
|
||||
|
||||
const form = reactive({
|
||||
first_name: null,
|
||||
last_name: null,
|
||||
email: null,
|
||||
})
|
||||
|
||||
function submit() {
|
||||
router.post('/users', form)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<h1>Create {{ page.modelName }}</h1>
|
||||
<form @submit.prevent="submit">
|
||||
<label for="first_name">First name:</label>
|
||||
<input id="first_name" v-model="form.first_name" />
|
||||
<label for="last_name">Last name:</label>
|
||||
<input id="last_name" v-model="form.last_name" />
|
||||
<label for="email">Email:</label>
|
||||
<input id="email" v-model="form.email" />
|
||||
<button type="submit">Submit</button>
|
||||
</form>
|
||||
</template>
|
||||
</code-snippet>
|
||||
@endverbatim
|
||||
@@ -0,0 +1,70 @@
|
||||
@php
|
||||
/** @var \Laravel\Boost\Install\GuidelineAssist $assist */
|
||||
@endphp
|
||||
## Inertia v2 + Vue Forms
|
||||
|
||||
@if($assist->inertia()->hasFormComponent())
|
||||
@boostsnippet("`<Form>` Component Example", "vue")
|
||||
<Form
|
||||
action="/users"
|
||||
method="post"
|
||||
#default="{
|
||||
errors,
|
||||
hasErrors,
|
||||
processing,
|
||||
progress,
|
||||
wasSuccessful,
|
||||
recentlySuccessful,
|
||||
setError,
|
||||
clearErrors,
|
||||
resetAndClearErrors,
|
||||
defaults,
|
||||
isDirty,
|
||||
reset,
|
||||
submit,
|
||||
}"
|
||||
>
|
||||
<input type="text" name="name" />
|
||||
|
||||
<div v-if="errors.name">
|
||||
{{ errors.name }}
|
||||
</div>
|
||||
|
||||
<button type="submit" :disabled="processing">
|
||||
{{ processing ? 'Creating...' : 'Create User' }}
|
||||
</button>
|
||||
|
||||
<div v-if="wasSuccessful">User created successfully!</div>
|
||||
</Form>
|
||||
@endboostsnippet
|
||||
@endif
|
||||
|
||||
@if($assist->inertia()->hasFormComponent() === false)
|
||||
{{-- Inertia 2.0.x, not 2.1.0 or higher. So still need to use 'useForm' --}}
|
||||
@boostsnippet("Inertia Vue useForm example", "vue")
|
||||
<script setup>
|
||||
import { useForm } from '@inertiajs/vue3'
|
||||
|
||||
const form = useForm({
|
||||
email: null,
|
||||
password: null,
|
||||
remember: false,
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<form @submit.prevent="form.post('/login')">
|
||||
<!-- email -->
|
||||
<input type="text" v-model="form.email">
|
||||
<div v-if="form.errors.email">{{ form.errors.email }}</div>
|
||||
<!-- password -->
|
||||
<input type="password" v-model="form.password">
|
||||
<div v-if="form.errors.password">{{ form.errors.password }}</div>
|
||||
<!-- remember me -->
|
||||
<input type="checkbox" v-model="form.remember"> Remember Me
|
||||
<!-- submit -->
|
||||
<button type="submit" :disabled="form.processing">Login</button>
|
||||
</form>
|
||||
</template>
|
||||
@endboostsnippet
|
||||
@endif
|
||||
@@ -0,0 +1,9 @@
|
||||
## Inertia + Vue
|
||||
|
||||
- Vue components must have a single root element.
|
||||
- Use `router.visit()` or `<Link>` for navigation instead of traditional links.
|
||||
|
||||
@boostsnippet("Inertia Client Navigation", "vue")
|
||||
import { Link } from '@inertiajs/vue3'
|
||||
<Link href="/">Home</Link>
|
||||
@endboostsnippet
|
||||
Reference in New Issue
Block a user