There are a few things I always dread implementing in every app I write. Modal dialogs (hard to get right on mobile,) and toasts / notifications / alerts / whatever. Not the native mobile / desktop push notifications, those are comparatively easy. The difficulty with toasts is building a flexible enough system to handle multiple notifications, actions in progress, various styles, various types of content, all while maintaining great animations for showing and hiding. It’s even worse if you want them to be interactive. vue-snotify
takes care of most of these use-cases with a simple API and great-looking notifications.
Install vue-snotify in your Vue.js project.
Now enable the plugin in the main Vue setup file.
Now, add the vue-snotify
component somewhere in your main app element. This is where the notifications will render.
From there, you can start using Snotify with the injected vm.$snotify
object. Here are some examples, though there’s plenty you can do with it.
All notifications can be configured with these properties.
Pretty much a boring old traditional classic normal (I’m running out of words here) notification.
All of these display a simple notification in their respective color.
Success
Error
Warning
Info
Snotify has a built-in system for asynchronous notifications, though they can be a bit tricky to understand. Here’s an example.
So basically async notifications should have an action
property that is a function that returns a promise. If that promise resolves, then the async notification is replaced with a success one. If it rejects, it’s replaced with an error. You can also resolve with another notification config object to display a custom success notification.
There are several other notification types that allow for user interaction as well, such as confirm, prompt, and html notifications. I won’t cover those here, as the official docs do a pretty good job. Take a look!
There’s also a great little playground available to test the various options available here. Enjoy!
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!