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

Commit e9fef7c

Browse files
committed
add main page
1 parent d02c8d4 commit e9fef7c

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

pages/_slug.vue

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<template>
2+
<section class="todoapp">
3+
<todo-header/>
4+
<section class="main" v-if="todos.length">
5+
<input class="toggle-all" type="checkbox" @click="allDone">
6+
<label for="toggle-all">Mark all as complete</label>
7+
<ul class="todo-list">
8+
<li v-for="todo in todos" :class="{'completed': todo.completed, 'editing': editedTodo === todo}">
9+
<div class="view">
10+
<input class="toggle" type="checkbox" v-model="todo.completed">
11+
<label @dblclick="editedTodo = todo">{{ todo.title }}</label>
12+
<button class="destroy" @click="removeTodo(todo)"></button>
13+
</div>
14+
<input class="edit" type="text" v-if="editedTodo === todo" v-model="editedTodo.title" @blur="editTodo(todo)" @keyup.enter="editTodo(todo)" @keyup.esc="editedTodo = null">
15+
</li>
16+
</ul>
17+
</section>
18+
<todo-footer/>
19+
</section>
20+
</template>
21+
22+
<script>
23+
import TodoHeader from '~components/header'
24+
import TodoFooter from '~components/footer'
25+
26+
export default {
27+
validate ({ params }) {
28+
return !params.slug || params.slug === 'active' || params.slug === 'completed'
29+
},
30+
head () {
31+
return {
32+
title: this.$route.params.slug || 'all',
33+
titleTemplate: 'Nuxt TodoMVC : %s todos'
34+
}
35+
},
36+
mounted () {
37+
this.$store.commit('fetch', JSON.parse(localStorage.getItem('nuxt-todos') || '[]'))
38+
},
39+
data () {
40+
return {
41+
editedTodo: null
42+
}
43+
},
44+
watch: {
45+
todos: {
46+
deep: true,
47+
handler: 'save'
48+
}
49+
},
50+
computed: {
51+
todos () {
52+
if (this.$route.params.slug === 'active') {
53+
return this.$store.getters.activeTodos
54+
}
55+
if (this.$route.params.slug === 'completed') {
56+
return this.$store.getters.completedTodos
57+
}
58+
return this.$store.getters.allTodos
59+
}
60+
},
61+
methods: {
62+
allDone () {
63+
this.$store.commit('allDone')
64+
},
65+
editTodo (todo) {
66+
if (!this.editedTodo.title) {
67+
this.$store.commit('remove', todo)
68+
}
69+
this.editedTodo = null
70+
},
71+
removeTodo (todo) {
72+
this.$store.commit('remove', todo)
73+
},
74+
save () {
75+
localStorage.setItem('nuxt-todos', JSON.stringify(this.todos))
76+
}
77+
},
78+
components: {
79+
TodoHeader,
80+
TodoFooter
81+
}
82+
}
83+
</script>

0 commit comments

Comments
 (0)