Skip to content
This repository was archived by the owner on Feb 1, 2021. It is now read-only.

Commit 51273a2

Browse files
committed
add components
1 parent 1795d1e commit 51273a2

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

components/footer.vue

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<template>
2+
<footer class="footer" v-if="todos.length">
3+
<span class="todo-count"><strong>{{ remaining }}</strong> item<span v-if="remaining > 1">s</span> left</span>
4+
<ul class="filters">
5+
<li>
6+
<nuxt-link to="/" exact>All</nuxt-link>
7+
</li>
8+
<li>
9+
<nuxt-link to="/active">Active</nuxt-link>
10+
</li>
11+
<li>
12+
<nuxt-link to="/completed">Completed</nuxt-link>
13+
</li>
14+
</ul>
15+
<button class="clear-completed" @click="removeCompleted" v-if="todos.length > remaining">
16+
Clear completed
17+
</button>
18+
</footer>
19+
</template>
20+
21+
<script>
22+
export default {
23+
computed: {
24+
todos () {
25+
return this.$store.getters.allTodos
26+
},
27+
actives () {
28+
return this.$store.getters.activeTodos
29+
},
30+
remaining () {
31+
return this.$store.getters.activeTodos.length
32+
}
33+
},
34+
methods: {
35+
removeCompleted () {
36+
this.$store.commit('removeCompleted', this.actives)
37+
}
38+
}
39+
}
40+
</script>

components/header.vue

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<template>
2+
<header class="header">
3+
<h1>todos</h1>
4+
<input class="new-todo" placeholder="What needs to be done?" autofocus v-model="todo" @keyup.enter="addTodo">
5+
</header>
6+
</template>
7+
8+
<script>
9+
export default {
10+
data () {
11+
return { todo: '' }
12+
},
13+
methods: {
14+
addTodo () {
15+
var value = this.todo && this.todo.trim()
16+
if (value) {
17+
this.$store.commit('add', { title: value, completed: this.$route.params.slug === 'completed' })
18+
this.todo = ''
19+
}
20+
}
21+
}
22+
}
23+
</script>

0 commit comments

Comments
 (0)