JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://unpkg.com/vue"></script>
<div id="app">
<button @click="createAlert">
Create Alert
</button>
<alert v-for="(alert, index) in alerts" :key="alert.id" :alert="alert" @expired="removeItem(alert)">{{ alert.id }}</alert>
</div>
</div>
JavaScript
Vue.component('alert', {
props: ["alert"],
template: '<li><slot></slot></li>',
mounted() {
setTimeout(() => this.$emit('expired', alert), 2000)
}
});
new Vue({
el: '#app',
data: {
count: 0,
alerts: []
},
methods: {
createAlert(){
this.alerts.push({id: this.count++})
},
removeItem(alert) {
console.log(alert)
this.alerts.splice(this.alerts.indexOf(alert), 1)
}
}
});