Vue
HTML
<div id="app">
<ol>
<li :class="del === key ? 'del' : ''" v-for="(todo, key) in todos" :key="key" @click="clickHandler(key)">{{ todo.text }}</li>
</ol>
</div>
CSS
li {
padding: 10px;
}
.del {
background: #ff0000;
}
Vue
new Vue({
el: "#app",
data: {
todos: [
{ text: "Learn JavaScript" },
{ text: "Learn Vue" },
{ text: "Play around in JSFiddle" },
{ text: "Build something awesome" }
],
del: null
},
methods: {
clickHandler (index) {
console.log(index)
let todos = document.querySelectorAll('li')
this.del = index
setTimeout(() => {
this.todos.splice(index, 1)
}, 1000)
}
}
})