Skip to content

Commit a0bd41a

Browse files
committed
Added btton to show all or show only incomplte tasks
1 parent 005e637 commit a0bd41a

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

app.js

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ let id = 0;
33
const app = Vue.createApp({
44
data() {
55
return {
6+
hideCompleted: false,
67
newTodo: '',
78
todos :[
89
{id: ++id, text: 'Try new app in Vue',done:true},
@@ -14,6 +15,11 @@ const app = Vue.createApp({
1415

1516
}
1617
},
18+
computed: {
19+
filteredList() {
20+
return this.hideCompleted ? this.todos.filter((t)=> !t.done) : this.todos
21+
}
22+
},
1723
methods: {
1824
addTodo() {
1925
this.todos.push({id: ++id, text: this.newTodo,done:false})

index.html

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ <h1>Simple To Do List in Vue-JS 3</h1>
1414
<input v-model="newTodo"></input>
1515
<button @click="addTodo()">Add Task</button>
1616
<ul>
17-
<li v-for="todo in todos" :key="todo.id">
17+
<li v-for="todo in filteredList" :key="todo.id">
1818
<input type="checkbox" v-model="todo.done">
1919
<span :class="{ completed: todo.done }">{{ todo.text }}</span>
2020
<button @click="removeTodo(todo)">Remove</button>
2121
</li>
2222
</ul>
23+
<button @click="hideCompleted = !hideCompleted">
24+
{{ hideCompleted ? "Show All Tasks" : "Hide Completed Tasks"}}
25+
</button>
2326
</div>
2427
</body>
2528
<script src="app.js"></script>

style.css

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ body{
66
}
77
.completed{
88
text-decoration: line-through;
9-
}
9+
}
10+
ul{padding:20px 0;margin:0;}
11+
ul li{list-style: none;padding-bottom: 10px;}
12+
span{margin-right: 10px;}

0 commit comments

Comments
 (0)