I am currently studying the Vue framework with this tutorial. The current episode is about Computed Properties. I have two lists of tasks, one with all of them and one with only those that are incomplete. With a button click the second list should be updated so it only shows tasks that are completed instead. I also want the message "Incomplete tasks" to change to "Completed tasks!. But how do I do all this without hassle?
The clue I received in the tutorial was this console command: app.tasks[0].completed = false;
HTML
<div id="computedList">
<h2>All Tasks</h2>
<ul>
<li v-for="task in tasks" v-text="task.description"></li>
</ul>
<h2>{{ message }}</h2>
<ul>
<li v-for="task in incompleteTasks" v-text="task.description"></li>
</ul>
<button @click="toggleClass">Complete Class</button>
<br>
</div>
JavaScript
var appb = new Vue({
el: '#computedList',
data: {
message: 'Incomplete tasks',
tasks: [
{description: 'Begin to study Vue', completed: true},
{description: 'Begin with the testapp', completed: true},
{description: 'Begin to study the ABB webbapp', completed: false},
{description: 'Begin to study Angular2', completed: false},
]
},
computed: {
incompleteTasks() {
return this.tasks.filter(task => !task.completed); //Filtrerar ovanstående lista!
}
},
methods: {
toggleClass() {
return this.tasks.filter(task => task.completed);
}
},
});
I want the solution to contain as little code as possible. Thanks!