--- 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 --- # 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 `resources/js/pages` directory. ### Page Component Structure ```vue ``` ## Client-Side Navigation ### Basic Link Component Use `` for client-side navigation instead of traditional `` tags: ```vue ``` ### Link with Method ```vue ``` ### Prefetching Prefetch pages to improve perceived performance: ```vue ``` ### Programmatic Navigation ```vue ``` ## Form Handling ### Form Component (Recommended) The recommended way to build forms is with the `` component: ```vue ``` ### Form Component With All Props ```vue ``` ### 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. ```vue ``` 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: ```vue ``` ## 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. ```vue ``` ### Optimistic Updates Apply data changes instantly before the server responds, with automatic rollback on failure: ```vue ``` Optimistic updates also work with `useForm` and the `` component: ```vue ``` ### 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. ```vue ``` ### Layout Props Share dynamic data between pages and persistent layouts: ```vue ``` ```vue ``` ### Deferred Props Use deferred props to load data after initial page render: ```vue ``` ### Polling Use the `usePoll` composable to automatically refresh data at intervals. It handles cleanup on unmount and throttles polling when the tab is inactive. ```vue ``` ```vue ``` - `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: ```vue ``` ### InfiniteScroll Automatically load additional pages of paginated data as users scroll: ```vue ``` 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