I have a todo list that is generated via jsonplaceholder , the button on click populates the div with dummy content.
What I am trying to achieve is that when I click on an individual div(task) it should be removed/hidden.
So far,
<button id="btn" v-on:click= 'getTodo'>Show Todo</button>
<div id="jsonData" v-for = 'todo in todos' >
<ul v-bind:class = '{active: isActive}' v-on:click = 'removeTask'>
<li>{{todo.title}} </li>
<li id="status"> Task Status : {{todo.completed}} </li>
</ul>
</div>
JS
var vm = new Vue({
el: '#app',
data() {
return {
todos: [],
isActive: false
}
},
methods: {
getTodo: function() {
axios.get('https://jsonplaceholder.typicode.com/todos')
.then((response) => {
this.todos = response.data;
})
},
removeTask: function() {
this.isActive = !this.isActive;
}
}
})
The 'removeTask' event handler toggles the classes for all the generated divs(tasks) and not to the clicked div.
How do I add/remove the class on the clicked div?
isActiveprop on the individual todo?isActiveto true/false which doesn't make sense when you want to manipulate the individual todo.