How to create an Alert in Vuetify that fade after specified number of seconds, similarly to the alerts in Bootstrap Vue. I tried this:
<template>
<transition name="fade">
<v-alert v-show="visible" v-bind="$attrs" v-on="$listeners">
<slot></slot>
</v-alert>
</transition>
</template>
<script>
export default {
inheritAttrs: true,
data() {
return {
visible: true,
timer: null
};
},
props: {
duration: {
required: true,
type: Number
}
},
methods: {
fade() {
let value = parseInt(Math.max(this.duration, 0));
if (value != 0)
this.timer = setTimeout(() => (this.visible = false), 1000 * value);
}
},
mounted() {
this.fade();
}
};
</script>
Usage in other components:
<vt-alert
v-if="hasMessage()"
:type="message.type"
:duration="message.duration"
>{{message.body}}</vt-alert>
hasMessage is utility function which check if the message is set.
But this did not work. More details here,