Vue Toastification

1.7.14 · active · verified Sun Apr 19

Vue Toastification is a versatile and highly customizable library for displaying toast notifications in Vue applications. It provides a simple, intuitive API for creating transient, dismissible messages with extensive configuration options for appearance, positioning, and behavior. The library currently offers a stable version 1.x (e.g., 1.7.14) for Vue 2, and a significant rewrite in version 2.x (currently in release candidate phase) specifically for Vue 3, which fully embraces the Composition API and a global event listener model. This design allows for easier integration and usage outside of traditional Vue components. Vue Toastification is actively maintained, with a focus on delivering robust SSR support, advanced customization through custom components, and a modern, Composition API-first approach in its upcoming major release. It differentiates itself with features like swipe-to-close, programmatic control over toasts, and comprehensive styling capabilities.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the setup of `vue-toastification` v2.x as a Vue 3 plugin and shows how to trigger different types of toasts, including custom component toasts, using the `useToast` Composition API hook.

import { createApp, h } from 'vue';
import App from './App.vue';
import Toast, { POSITION, TYPE } from 'vue-toastification';
import 'vue-toastification/dist/index.css';

const app = createApp(App);

app.use(Toast, {
  position: POSITION.BOTTOM_RIGHT,
  timeout: 3000,
  closeOnClick: true,
  pauseOnFocusLoss: true,
  pauseOnHover: true,
  draggable: true,
  draggablePercent: 0.6,
  showCloseButtonOnHover: false,
  hideProgressBar: false,
  closeButton: 'button',
  icon: true,
  rtl: false,
  maxToasts: 5,
  newestOnTop: true,
});

app.mount('#app');

// Inside your App.vue or any other component's <script setup>
// <template>
//   <div>
//     <button @click="showSuccessToast">Show Success</button>
//     <button @click="showErrorToast">Show Error</button>
//     <button @click="showCustomComponentToast">Show Custom Component Toast</button>
//   </div>
// </template>

// <script setup lang="ts">
// import { useToast } from 'vue-toastification';

// const toast = useToast();

// const showSuccessToast = () => {
//   toast.success('Your changes have been saved!');
// };

// const showErrorToast = () => {
//   toast.error('An error occurred. Please try again.');
// };

// const showCustomComponentToast = () => {
//   const CustomToast = h('div', { class: 'my-custom-toast' }, [
//     h('h4', 'Custom Title'),
//     h('p', 'This toast is rendered from a custom component!'),
//     h('button', { onClick: () => toast.clear() }, 'Clear All Toasts')
//   ]);
//   toast(CustomToast, {
//     type: TYPE.INFO,
//     timeout: false, // Make it persistent
//     closeButton: false,
//   });
// };
// </script>

view raw JSON →