I want to ask You how I can define a method which execute after the timeout
? After that timeout
i want to execute $emit
event, but I don't know how can i do this...
<v-snackbar
v-model="snackbar"
:color="primary"
:timeout="5000"
>
{{ text }}
<v-btn
dark
flat
@click="snackbar = false"
>
Close
</v-btn>
</v-snackbar>
https://vuetifyjs.com/en/components/snackbars
We can create snackbars in Vuetify using the v-snackbar component. In the code below, we create a "Close" button in the action slot of the snackbar. When this button is clicked, the snackbar variable is set to false to hide the snackbar. snackbar is false by default, so at first we can only see the button that opens the snackbar:
The timeout property lets you customize the delay before the v-snackbar is hidden. Apply different styles to the snackbar using props such as text, shaped, outlined, and more.
A snackbar helps to display quick messages. We can use it to notify users of certain events that occur in an app (for example, deleting an item from a list). They might also contain actions related to the information shown that users can take. In this article, we’re going to learn how to create snackbars using the Vuetify framework.
The multi-line property extends the height of the v-snackbar to give you a little more room for content. The timeout property lets you customize the delay before the v-snackbar is hidden. Apply different styles to the snackbar using props such as text, shaped, outlined, and more.
According to the documentation there's no event attached to that property, but i will give a solution that responds to your use case, add timeout
property to your data object as follows :
data() {
return {
snackbar:false,
timeout:6000,
....
}
}
add an event handler to your button click :
<v-btn block
color="primary"
dark
@click="showSnackbar">
Show Snackbar
</v-btn>
in your methods add showSnackbar
method
methods: {
showSnackbar() {
this.snackbar=true;
setTimeout(() => { this.$emit("yourEvent"); },this.timeout);
}
}
I simulate a your case in this pen
You could also use a watcher. Watch for snackbar === false
, then execute the function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With