Vuetify Toast Snackbar Demo

Vuetify Toast Snackbar Demo

In this tutorial, we'll create a Vuetify toast snackbar that displays a message for 10 seconds. We'll walk through the code you provided to understand how it works and demonstrate its functionality.

Profile Photo

Abhishek Yadav (SD) SDE of FAI

Feedback

written
Profile Photo

Anil Kumar (Expert) Coding Expert of FAI

Feeback

reviewed
Profile Photo
Oct 30, 2023 06:10 AM Last Updated
updated

Vuetify Show Toast for 10 Seconds

Copied to Clipboard
Run

Code Explanation

Let's break down the code

Copied to Clipboard
  • The v-app and v-container elements are part of Vuetify's layout structure.
  • The v-snackbar component is used to display the toast message. Its v-model is bound to the snackbar data property, controlling its visibility.
  • The :timeout="10000" attribute sets the timeout for the snackbar to 10 seconds.
  • Inside the snackbar, {{ snackbarText }} is used to display the text.
  • The v-btn element is used to close the snackbar when clicked, setting snackbar to false.
  • Another v-btn triggers the showSnackbar method when clicked

Copied to Clipboard
  • We use Vue.js to create the app.
  • data contains the snackbar property to control the snackbar's visibility and snackbarText for the message.
  • The showSnackbar method sets snackbar to true, displaying the snackbar.
  • We use Vuetify to enhance the app's UI.
  • Finally, we mount the app to the HTML element with the ID "app."

Conclusion

With this code, when you click the "Show Toast for 10 Seconds" button, the snackbar appears with the message "My timeout is set to 10000." It will automatically disappear after 10 seconds.

This Vuetify toast snackbar is a useful UI component for displaying temporary messages or notifications in your Vue.js applications

Output of Vuetify Toast Notification

Pasted Image

 

Ad