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.
written
reviewed
updated
Thanks for your feedback!
Your contributions will help us to improve service.
Code Explanation
Let's break down the code
Copied to Clipboard
- The
v-app
andv-container
elements are part of Vuetify's layout structure. - The
v-snackbar
component is used to display the toast message. Itsv-model
is bound to thesnackbar
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, settingsnackbar
tofalse
. - Another
v-btn
triggers theshowSnackbar
method when clicked
Copied to Clipboard
- We use Vue.js to create the app.
data
contains thesnackbar
property to control the snackbar's visibility andsnackbarText
for the message.- The
showSnackbar
method setssnackbar
totrue
, 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
Ad