--- 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 --- # Inertia Vue Development ## 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. ```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 ### `useForm` Composable For Inertia v2.0.x: Build forms using the `useForm` composable as the `` component is not available until v2.1.0+. ```vue ``` ## Inertia v2 Features ### 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 (Infinite Scroll) Load more data when user scrolls to a specific element: ```vue ``` ## 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