Answer the question
In order to leave comments, you need to log in
How to make multiple elements disappear randomly in vuejs?
I am new to vue. I can't think. It is necessary to make several messages, which will disappear at different speeds.
those.
<message>Сообщение исчезнет через 5 секунд</message>
<message>Сообщение исчезнет через 20 секунд</message>
<message>Сообщение исчезнет через 15 секунд</message>
<template>
<div class="alert alert-dismissible fade show"
v-bind:class="[currentClass]"
>
<button type="button" aria-hidden="true" class="close" data-dismiss="alert" aria-label="Close">
<i class="nc-icon nc-simple-remove"></i>
</button>
<span> {{ message }}</span>
</div>
</template>
<script>
export default {
name: "Alert",
props: [
'message', 'currentClass'
],
}
</script>
<alert
v-for="(item,index) in alertsArr"
:key="index"
:message="item.message"
:current-class="item.currentClass"
></alert>
export default {
components: {
alert: Alert
},
methods: {
setAlert() {
this.addAlert("da", "alert-danger ", 1000);
},
addAlert(message, currentClass, time) {
this.$set(this.alertsArr, this.indexOfAlerts, {
'message': message,
'currentClass': currentClass,
});
setTimeout(function () {
this.$delete(this.alertsArr, this.indexOfAlerts);
// console.info(this.alertsArr);
this.indexOfAlerts++;
}.bind(this), time);
},
},
data() {
return {
alertsArr: [],
indexOfAlerts: 0,
Answer the question
In order to leave comments, you need to log in
So far, all I have figured out is what needs to be done through v-for, for each message do v-if , the visible field, I will change it by timeout, it will disappear. But this doesn't seem optimal to me.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question