Inertia Vue Development
When to Apply
Activate this skill when:
- Creating or modifying Vue page components for Inertia
- Working with forms in Vue (using
<Form>oruseForm) - Implementing client-side navigation with
<Link>orrouter - Using v2 features: deferred props, prefetching, or polling
- Building Vue-specific features with the Inertia protocol
Documentation
Use search-docs for detailed Inertia v2 Vue patterns and documentation.
Basic Usage
Page Components Location
Vue page components should be placed in the resources/js/pages directory.
Page Component Structure
Important: Vue components must have a single root element.
Client-Side Navigation
Basic Link Component
Use <Link> for client-side navigation instead of traditional <a> tags:
Link with Method
Prefetching
Prefetch pages to improve perceived performance:
Programmatic Navigation
Form Handling
Form Component (Recommended)
The recommended way to build forms is with the <Form> component:
<input type="email" name="email" />
<div v-if="errors.email">{{ errors.email }}</div>
<button type="submit" :disabled="processing">
{{ processing ? 'Creating...' : 'Create User' }}
</button>
<div v-if="wasSuccessful">User created!</div>
</Form>
Form Component With All Props
<button type="submit" :disabled="processing">
{{ processing ? 'Saving...' : 'Save' }}
</button>
<progress v-if="progress" :value="progress.percentage" max="100">
{{ progress.percentage }}%
</progress>
<div v-if="wasSuccessful">Saved!</div>
</Form>
Form Component Reset Props
The <Form> component supports automatic resetting:
resetOnError- Reset form data when the request failsresetOnSuccess- Reset form data when the request succeedssetDefaultsOnSuccess- Update default values on success
Use the search-docs tool with a query of form component resetting for detailed guidance.
<button type="submit" :disabled="processing">
Submit
</button>
</Form>
Forms can also be built using the useForm composable for more programmatic control. Use the search-docs tool with a query of useForm helper for guidance.
useForm Composable
For more programmatic control or to follow existing conventions, use the useForm composable:
<input type="email" v-model="form.email" />
<div v-if="form.errors.email">{{ form.errors.email }}</div>
<input type="password" v-model="form.password" />
<div v-if="form.errors.password">{{ form.errors.password }}</div>
<button type="submit" :disabled="form.processing">
Create User
</button>
</form>
Inertia v2 Features
Deferred Props
Use deferred props to load data after initial page render:
Polling
Automatically refresh data at intervals:
WhenVisible (Infinite Scroll)
Load more data when user scrolls to a specific element:
<WhenVisible
v-if="users.next_page_url"
data="users"
:params="{ page: users.current_page + 1 }"
>
<template #fallback>
<div>Loading more...</div>
</template>
</WhenVisible>
</div>
Server-Side Patterns
Server-side patterns (Inertia::render, props, middleware) are covered in inertia-laravel guidelines.
Common Pitfalls
- Using traditional
<a>links instead of Inertia's<Link>component (breaks SPA behavior) - Forgetting that Vue components must have a single root element
- Forgetting to add loading states (skeleton screens) when using deferred props
- Not handling the
undefinedstate of deferred props before data loads - Using
<form>without preventing default submission (use<Form>component or@submit.prevent) - Forgetting to check if
<Form>component is available in your Inertia version
