--- title: "Vue 3 Composable and Plugin" description: "Use Laravel Inertia Toast with Vue 3, including plugin registration, toast composables, confirmation modals, and the Inertia flash bridge." head: - - meta - name: robots content: 'index, follow, max-image-preview:large, max-snippet:-1, max-video-preview:-1' - - meta - name: googlebot content: 'index, follow, max-image-preview:large, max-snippet:-1, max-video-preview:-1' - - meta - name: bingbot content: 'index, follow, max-image-preview:large, max-snippet:-1, max-video-preview:-1' --- # Vue Usage The Vue package handles rendering, client-side notifications, and promise-based confirmations. ## Plugin registration Register the plugin once in your Inertia bootstrap file: ```ts import ToastPlugin from '@erag/inertia-toast-vue'; import '@erag/inertia-toast-vue/style.css'; app.use(ToastPlugin, { position: 'bottom-right', }); ``` The plugin mounts: - `ToastContainer` - `ConfirmationBox` - `FlashToastBridge` ## Plugin options ```ts type ToastPosition = | 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right'; interface PluginOptions { position?: ToastPosition; } ``` ## `useToast()` Use `useToast()` when you want to trigger client-side notifications without waiting for a Laravel redirect. ```ts import { useToast } from '@erag/inertia-toast-vue'; const toast = useToast(); toast.success('Saved successfully'); toast.error('Unable to save', 'Error'); toast.warning('Disk space is low', 'Warning', 5000, 'top-right'); toast.info('Background sync started', 'Info'); ``` ### In a component ```vue ``` ## `useConfirmation()` The confirmation composable returns a promise, which makes destructive flows simple to write. ```ts import { useConfirmation } from '@erag/inertia-toast-vue'; const { confirm } = useConfirmation(); const accepted = await confirm({ title: 'Delete record', message: 'This action cannot be undone.', confirmText: 'Delete', cancelText: 'Cancel', type: 'danger', }); ``` ### Delete flow with Inertia router ```vue ``` ## Flash bridge behavior The plugin includes `FlashToastBridge`, which does two things automatically: 1. Reads the initial `data-page` payload rendered by Inertia. 2. Listens for later `inertia:success` events and checks `page.props.toast`. That is why Laravel flash toasts appear automatically after redirects and later visits. ## Practical guidance - Use Laravel `toast()` for redirect-based success and error messages. - Use `useToast()` for purely client-side actions. - Use `useConfirmation()` before destructive requests, then let Laravel return the final success toast. To see these patterns running side by side, open the [live demo](./demo.html).