useToast
TheuseToast composable provides programmatic access to toast notifications. Use it to create, remove, or clear toasts from anywhere in your Vue components.
Usage
Return type
Properties
ComputedRef<ToastItem[]>
Reactive computed reference to all currently active toast items. Updates automatically when toasts are added or removed.
ComputedRef<ToastConfig>
Reactive computed reference to the current toast configuration. Reflects the global settings configured through the plugin.
Methods
success
(message: string, options?: ToastOptions) => void
Display a success toast notification.Parameters:Example:
string
required
The main message to display in the toast.
ToastOptions
error
(message: string, options?: ToastOptions) => void
info
(message: string, options?: ToastOptions) => void
warning
(message: string, options?: ToastOptions) => void
remove
(id: string) => void
Manually remove a specific toast by its ID.Parameters:Example:
string
required
The unique identifier of the toast to remove.
clear
() => void
Remove all active toasts immediately.Example:
Complete example
The composable uses Vue’s reactivity system. All returned properties are reactive and will automatically update your components when toasts are added or removed.