@vex-ui/toast
v0.0.2
Published
A simple and customizable toast notification system for Vue 3 applications.
Downloads
6
Maintainers
Readme
Vex Toast
this is a small unstyled toast service library for Vue 3.
installation
pnpm i @vex-ui/toast
usage
- register the plugin in your app.
import { createApp } from 'vue'
import VexPlugin from '@vex/toast'
const app = createApp()
app.use(VexPlugin, {})
app.mount()
- use the
useToast
composable to access thetoastify
andtoasts
data, then use theToast
andToastProvider
components to display the toasts, usedismiss
function to dismiss them.
import { useToast } from '@vex/toast'
const { toastify, toasts, dismiss } = useToast()
<template>
<ToastProvider>
<Toast
@timer-end="dismiss(item.uuid)"
v-for="item in toasts"
v-bind="item"
:key="item.uuid"
/>
</ToastProvider>
</template>
- use the
toastify
function to display a toast.
import { useToast } from '@vex/toast'
const { toastify, toasts } = useToast()
// anything you pass on the first argument will be available inside item.meta in the template.
toastify({ message: 'Hello!' }, { duration: 3000 })
<template>
<ToastProvider>
<Toast
@timer-end="dismiss(item.uuid)"
v-for="item in toasts"
v-bind="item"
:key="item.uuid"
>
<h2>{{ item.meta.message }}</h2>
</Toast>
</ToastProvider>
</template>