Skip to main content

useToast

The useToast 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:
string
required
The main message to display in the toast.
ToastOptions
Optional configuration for this specific toast.
string
Optional title displayed above the message in semibold font.
number
Custom duration in milliseconds for this toast. Overrides the global duration setting.
Example:

error

(message: string, options?: ToastOptions) => void
Display an error toast notification.Parameters:
string
required
The error message to display.
ToastOptions
Optional configuration for this specific toast.
Example:

info

(message: string, options?: ToastOptions) => void
Display an informational toast notification.Parameters:
string
required
The informational message to display.
ToastOptions
Optional configuration for this specific toast.
Example:

warning

(message: string, options?: ToastOptions) => void
Display a warning toast notification.Parameters:
string
required
The warning message to display.
ToastOptions
Optional configuration for this specific toast.
Example:

remove

(id: string) => void
Manually remove a specific toast by its ID.Parameters:
string
required
The unique identifier of the toast to remove.
Example:

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.