Use o composable useToast, importado automaticamente, para exibir notificações Toast.
useToast composable uses Nuxt's useState to manage the toast state, ensuring reactivity across your application.App, que usa nosso componente Toaster, que por sua vez usa o componente ToastProvider do Reka UI.useToast()
O composable useToast fornece métodos para gerenciar as notificações toast globalmente.
add(toast: Partial<Toast>): Toast
Adds a new toast notification.
Toast object with the following properties:true.vertical.false value). Defaults to true.false value). Defaults to true.App component.Returns: The complete Toast object that was added.
<script setup lang="ts">
const toast = useToast()
function showToast() {
toast.add({
title: 'Success',
description: 'Your action was completed successfully.',
color: 'success'
})
}
</script>
update(id: string | number, toast: Partial<Toast>): void
Updates an existing toast notification.
Toast object with the properties to update.<script setup lang="ts">
const toast = useToast()
function updateToast(id: string | number) {
toast.update(id, {
title: 'Updated Toast',
description: 'This toast has been updated.'
})
}
</script>
remove(id: string | number): void
Removes a toast notification.
<script setup lang="ts">
const toast = useToast()
function removeToast(id: string | number) {
toast.remove(id)
}
</script>
clear(): void
Removes all toast notifications.
<script setup lang="ts">
const toast = useToast()
function clearAllToasts() {
toast.clear()
}
</script>
toasts: Ref<Toast[]>
A reactive array containing all current toast notifications.
<script setup lang="ts">
const { toasts } = useToast()
</script>
<template>
<div>
<pre>{{ toasts }}</pre>
</div>
</template>