Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

vue-toastify

nandi954kMIT2.1.0TypeScript support: included

Simple and dependency-free notification plugin.

vue, toast, notification, vue3, alert, vue-toastify, vue-toast, snackbar, toast-notification, notice, toastify, toast-component, toast-plugin, toastify-component, vue-notification

readme

🔥Vue Toastify🔥

Simple and dependency-free notification plugin.

Installation

npm i vue-toastify
import { createApp } from 'vue';
import plugin from 'vue-toastify';
// base styles
import 'vue-toastify/index.css';
// theme styles
import 'vue-toastify/themes/dark.css';
import type { Settings } from 'vue-toastify';

const app = createApp({  });
app.use<Settings>(plugin, {  });
app.mount('#app');

Usage with Nuxt

Options:

Migration Information

In the future enableHtmlInterpretation setting will default to false. If you rely on that behavior, make sure to enable it in the settings. If you don't want user input treated as html, make sure to set it to false.

Custom styling

Styles include a 'dark'(default) and a 'light' theme. If you would like to create your own styles you may use the following helpers:

import { createVtTheme, getCssRules } from 'vue-toastify';

// this will create a stylesheet if doesn't exists and insert it into the head
createVtTheme('myThemeName', '#8f6b42');
// then you can set the theme of the status or the global settings
// alternatively, you can get an array of css rules using getCssRules
getCssRules('myThemeName', '#8f6b42').forEach(rule => {...});
// this will give you a good starting point to customise the theme

Custom notifications

You may create some methods on the useToast() so it will shortcut any repetition you may have in your app. To register them add a customNotifications key to the settings when registering the plugin.

app.use<Settings>(plugin, {
    customNotifications: {
        authenticationError: {
            body: 'Authentication error',
            // ... rest of the toast options here
        }
    }
});
// then later you can use it as
useToast().authenticationError();

Ambient declaration for custom notifications

import type { ToastPluginAPI, CustomMethods } from 'vue-toastify';

declare module 'vue-toastify' {
    interface MyMethods extends CustomMethods {
        authenticationError(): string;
    }

    function useToast(): ToastPluginAPI & MyMethods;
}

Events

The plugin emits events that you can listen to which allows for using callbacks at different points in the toast's lifecycle.

import { useVtEvents, useToast } from 'vue-toastify';

const toast = useToast().success({ body: 'Hello world', canTimeout: true });

useVtEvents().once('vtPaused', payload => {
    if (payload.id === toast.id) {
        // do something
    }
})

Usage with Nuxt

The recommended way to install is by creating a plugin. As notifications are expected to be responses to user actions, we can lazy load the plugin to reduce the initial bundle size.

Be sure to familiarise yourself with the Nuxt plugin documentation.

// plugins/toast.client.ts
// .client will only run the plugin on the client side.
import type { Settings } from 'vue-toastify';

export default defineNuxtPlugin({
    name: 'toast',
    // can load the same time as the rest of the plugins
    parallel: true,
    setup: nuxt => {
        // this will lazy load the plugin therefore won't be included in the entry point
        void import('vue-toastify').then(exports => {
            nuxt.vueApp.use<Settings>(exports.default, {
                pauseOnHover: true,
                theme: 'light',
                position: 'top-right'
            });
        });
    }
});

Then specify the auto-imported preset in your configuration.

// nuxt.config.ts
export default defineNuxtConfig({
    css: [
        // required base themes
        'vue-toastify/index.css',
        // include the theme you want to use
        'vue-toastify/themes/light.css'
        // or generate one of your own as described in the custom styling section
    ],
    imports: {
        // this will include the composables that the plugin provides
        // which is negligable in size compared to the plugin itself
        presets: [
            {
                from: 'vue-toastify',
                imports: [
                    // include only the composables you need auto-imported
                    'useToast',
                    // 'useVtEvents',
                    // 'useVtSettings'
                ]
            }
        ]
    },
})

changelog

v2.1.0 15/03/2025

Chore:

  • Add a missing build step
  • Convert toast container to setup for better type inference

Fix:

  • fix typings internal to the package/demo
  • fix toast sizing issue on chrome
  • fix logic for getting title - respect defaultTitle setting
  • added enableHtmlInterpretation flag enabling v-html input for the body and icon (xss risk)
  • fix text legibility issue on theme generator
  • fix centering issue on small screens

Feature:

  • Add JSX support for body and icon
  • updated dependencies
  • added some a11y attributes
  • allow overwriting built in methods with customNotifications

v2.0.1 11/09/2024

Chore:

  • Add a missing build step

v2.0.0 10/09/2024

Performance:

  • BREAKING: removed include of all styles by default. You now have to import the base styles AND the theme you want to use.
  • Add will-change for transitioning toasts too.
  • Added separate exports for composables.

Fix:

  • Fixed toast might stay on screen if the duration is very low.

Chore:

  • Fixed eslint issues.
  • Updated dependencies.
  • Updated demo app styling.
  • Documented nuxt usage.

v2.0.0-alpha 13/04/2023

Refactor:

  • Rewritten codebase using v3 of Vue, and its composition api.
  • Removed support for passing in router to the plugin. (Developer can just use the callback option)
  • Added pauseOnFocusLoss option to pause the timer when the window loses focus.
  • Added dynamic theme creation

v1.8.1 25/11/2021

Fix:

  • Resolved xss vulnerability stemming from an url option not being encoded (#26).

v1.8.0 05/05/2020

Feature:

  • Added a new event for when the notification is being dragged.
  • Drag event payloads now also include the position of the notification.
  • Added toastify to the vue as a static method for easier handling in vuex.

v1.7.0 28/03/2020

Feature:

  • Added vue router support to the url setting.
  • getSettings() can now return a single setting's value, given the key.

    Fix:

  • changeToast now returns false as expected when the toast isn't found.

v1.6.1 11/03/2020

Fix:

  • Drag behavior fixed to the toast not only the parent element.
  • Added will change optimisation to dragging.

v1.6.0 10/03/2020

Feature:

  • Added one type at a time option.
  • Added max number of notifications on screen option.
  • Added getSettings() function. (This is more verbose than setSettings({}))

    Fix:

  • Concatenated queue with toasts on getToast and added return value on not found.
  • Fixed positioning of the toast on singular dismiss
  • Fixed stopLoader when passed an array of ids

v1.5.2 20/01/2020

Fix:

  • Fixed width issue with long content on leave transition.

v1.5.1 20/01/2020

Fix:

  • Added extra check for icon selection.

v1.5.0 19/01/2020

Fix:

  • Added the return statement to the custom notification methods
  • Fixed the setSettings when using with falsy value.
  • Added logic to delay the notification move on removal
  • Fixed transition positions
  • Added more style namespaces and a whitelist pattern

    Feature:

  • Added draggable option to dismiss toast by dragging.
  • Added function to listen for events emitted by the notifications.

v1.4.0 03/01/2020

Fix:

  • Removed bodyMaxWidth from props and added to the styles
  • Updated adding feature to return id instead of currently showing toasts if it is in singular mode.
  • Removed prototype builtins.
  • Added missing checks for notification coming from server.
  • Added packages for testing.
  • Styling adjustment for the notification content

    Feature:

  • Added sass functions for easier theme creation
  • Added option for accepting icons in object format

v1.3.1 27/12/2019

Fix:

  • Removed polyfills from bundle

v1.3.0 27/12/2019

Fix:

  • Container now ignores clicks thanks to pointer-events: none;
  • Better responsiveness added to the toasts
  • Fixed notification timeout close logic
  • General refactor for maintainability
  • The status' title attribute will no longer get capitalised (Sorry I didn't see major bump version justified)

    Feature:

  • Moved transition into group transition for using the FLIP technique
  • Added notification display ordering option
  • Plugin now accepts custom transitions