--- name: inertia-vue-development description: "Develops Inertia.js v3 Vue client-side applications. Activates when creating Vue pages, forms, or navigation; using ,
, useForm, useHttp, setLayoutProps, or router; working with deferred props, prefetching, optimistic updates, instant visits, or polling; or when user mentions Vue with Inertia, Vue pages, Vue forms, or Vue navigation." license: MIT metadata: author: laravel --- @php /** @var \Laravel\Boost\Install\GuidelineAssist $assist */ @endphp # Inertia Vue Development ## When to Apply Activate this skill when: - Creating or modifying Vue page components for Inertia - Working with forms in Vue (using ``, `useForm`, or `useHttp`) - Implementing client-side navigation with `` or `router` - Using v3 features: deferred props, prefetching, optimistic updates, instant visits, layout props, HTTP requests, WhenVisible, InfiniteScroll, once props, flash data, or polling - Building Vue-specific features with the Inertia protocol ## Documentation Use `search-docs` for detailed Inertia v3 Vue patterns and documentation. ## Basic Usage ### Page Components Location Vue page components should be placed in the `{{ $assist->inertia()->pagesDirectory() }}` directory. ### Page Component Structure @verbatim @boostsnippet("Basic Vue Page Component", "vue") @endboostsnippet @endverbatim ## Client-Side Navigation ### Basic Link Component Use `` for client-side navigation instead of traditional `` tags: @boostsnippet("Inertia Vue Navigation", "vue") @endboostsnippet ### Link with Method @boostsnippet("Link with POST Method", "vue") @endboostsnippet ### Prefetching Prefetch pages to improve perceived performance: @boostsnippet("Prefetch on Hover", "vue") @endboostsnippet ### Programmatic Navigation @boostsnippet("Router Visit", "vue") @endboostsnippet ## Form Handling @if($assist->inertia()->hasFormComponent()) ### Form Component (Recommended) The recommended way to build forms is with the `` component: @verbatim @boostsnippet("Form Component Example", "vue") @endboostsnippet @endverbatim ### Form Component With All Props @verbatim @boostsnippet("Form Component Full Example", "vue") @endboostsnippet @endverbatim @if($assist->inertia()->hasFormComponentResets()) ### Form Component Reset Props The `` component supports automatic resetting: - `resetOnError` - Reset form data when the request fails - `resetOnSuccess` - Reset form data when the request succeeds - `setDefaultsOnSuccess` - Update default values on success Use the `search-docs` tool with a query of `form component resetting` for detailed guidance. @verbatim @boostsnippet("Form with Reset Props", "vue") @endboostsnippet @endverbatim @else Note: This version of Inertia does not support `resetOnError`, `resetOnSuccess`, or `setDefaultsOnSuccess` on the `` component. Using these props will cause errors. Upgrade to Inertia v2.2.0+ to use these features. @endif 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. @endif ### `useForm` Composable @if($assist->inertia()->hasFormComponent() === false) For Inertia v2.0.x: Build forms using the `useForm` composable as the `` component is not available until v2.1.0+. @else For more programmatic control or to follow existing conventions, use the `useForm` composable: @endif @verbatim @boostsnippet("useForm Composable Example", "vue") @endboostsnippet @endverbatim ## Inertia v3 Features ### HTTP Requests Use the `useHttp` hook for standalone HTTP requests that do not trigger Inertia page visits. It provides the same developer experience as `useForm`, but for plain JSON endpoints. @boostsnippet("useHttp Example", "vue") @endboostsnippet ### Optimistic Updates Apply data changes instantly before the server responds, with automatic rollback on failure: @boostsnippet("Optimistic Update with Router", "vue") @endboostsnippet Optimistic updates also work with `useForm` and the `` component: @verbatim @boostsnippet("Optimistic Update with Form Component", "vue") @endboostsnippet @endverbatim ### Instant Visits Navigate to a new page immediately without waiting for the server response. The target component renders right away with shared props, while page-specific props load in the background. @boostsnippet("Instant Visit with Link", "vue") @endboostsnippet ### Layout Props Share dynamic data between pages and persistent layouts: @verbatim @boostsnippet("Layout Props in Layout", "vue") @endboostsnippet @endverbatim @boostsnippet("Setting Layout Props from Page", "vue") @endboostsnippet ### Deferred Props Use deferred props to load data after initial page render: @verbatim @boostsnippet("Deferred Props with Empty State", "vue") @endboostsnippet @endverbatim ### Polling Use the `usePoll` composable to automatically refresh data at intervals. It handles cleanup on unmount and throttles polling when the tab is inactive. @verbatim @boostsnippet("Basic Polling", "vue") @endboostsnippet @endverbatim @verbatim @boostsnippet("Polling With Request Options and Manual Control", "vue") @endboostsnippet @endverbatim - `autoStart` (default `true`) - set to `false` to start polling manually via the returned `start()` function - `keepAlive` (default `false`) - set to `true` to prevent throttling when the browser tab is inactive ### WhenVisible Lazy-load a prop when an element scrolls into view. Useful for deferring expensive data that sits below the fold: @verbatim @boostsnippet("WhenVisible Example", "vue") @endboostsnippet @endverbatim ### InfiniteScroll Automatically load additional pages of paginated data as users scroll: @verbatim @boostsnippet("InfiniteScroll Example", "vue") @endboostsnippet @endverbatim The server must use `Inertia::scroll()` to configure the paginated data. Use the `search-docs` tool with a query of `infinite scroll` for detailed guidance on buffers, manual loading, reverse mode, and custom trigger elements. ## Server-Side Patterns Server-side patterns (Inertia::render, props, middleware) are covered in inertia-laravel guidelines. ## Common Pitfalls - Using traditional `` links instead of Inertia's `` 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 `undefined` state of deferred props before data loads - Using `` without preventing default submission (use `` component or `@submit.prevent`) - Forgetting to check if `` component is available in your Inertia version - Using `router.cancel()` instead of `router.cancelAll()` (v3 breaking change) - Using `router.on('invalid', ...)` or `router.on('exception', ...)` instead of the renamed `httpException` and `networkError` events