--- name: inertia-vue-development description: "Develops Inertia.js v2 Vue client-side applications. Activates when creating Vue pages, forms, or navigation; using ,
, useForm, or router; working with deferred props, prefetching, 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 ## Documentation Use `search-docs` for detailed Inertia v2 Vue patterns and documentation. ## Basic usage ### Page components location Place Vue page components in the `{{ $assist->inertia()->pagesDirectory() }}` directory. ### Page component structure Important: Vue components must have a single root element. @verbatim @boostsnippet("Basic Vue Page Component", "vue") @endboostsnippet @endverbatim ## Client-side navigation ### Basic Link component Use `` for client-side navigation instead of `` 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 For details, run the `search-docs` tool with the query `form component resetting`. @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 causes errors. To use these props, upgrade to Inertia v2.2.0+. @endif For more programmatic control, you can also build forms with the `useForm` composable. For guidance, run the `search-docs` tool with the query `useForm helper`. @endif ### `useForm` composable @if($assist->inertia()->hasFormComponent() === false) In Inertia v2.0.x, build forms with the `useForm` composable. 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 v2 features ### Deferred props Use deferred props to load data after the initial page render: @verbatim @boostsnippet("Deferred Props with Empty State", "vue") @endboostsnippet @endverbatim ### Polling Use the `usePoll` composable to refresh data automatically at intervals. The composable cleans up on unmount and throttles polling when the browser tab is inactive. @boostsnippet("Basic Polling", "vue") @endboostsnippet @boostsnippet("Polling With Request Options and Manual Control", "vue") @endboostsnippet - `autoStart` (default `true`): set to `false` to start polling manually with the returned `start()` function - `keepAlive` (default `false`): set to `true` to prevent throttling when the browser tab is inactive ### WhenVisible (infinite scroll) Load more data when the user scrolls to a specific element: @verbatim @boostsnippet("Infinite Scroll with WhenVisible", "vue") @endboostsnippet @endverbatim ## Server-side patterns The inertia-laravel guidelines cover server-side patterns such as Inertia::render, props, and middleware. ## 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 the `` component or `@submit.prevent`) - Forgetting to check whether the `` component is available in your Inertia version