|
@@ -9,7 +9,7 @@
|
|
autofocus
|
|
autofocus
|
|
autocomplete="off"
|
|
autocomplete="off"
|
|
placeholder="What needs to be done?"
|
|
placeholder="What needs to be done?"
|
|
- @keyup.enter="addTodo">
|
|
|
|
|
|
+ @keyup.enter="tryAddTodo">
|
|
</header>
|
|
</header>
|
|
<!-- main section -->
|
|
<!-- main section -->
|
|
<section class="main" v-show="todos.length">
|
|
<section class="main" v-show="todos.length">
|
|
@@ -47,6 +47,11 @@
|
|
|
|
|
|
<script>
|
|
<script>
|
|
import Todo from './Todo.vue'
|
|
import Todo from './Todo.vue'
|
|
|
|
+import {
|
|
|
|
+ addTodo,
|
|
|
|
+ toggleAll,
|
|
|
|
+ clearCompleted
|
|
|
|
+} from '../store/actions'
|
|
|
|
|
|
const filters = {
|
|
const filters = {
|
|
all: (todos) => todos,
|
|
all: (todos) => todos,
|
|
@@ -56,6 +61,16 @@ const filters = {
|
|
|
|
|
|
export default {
|
|
export default {
|
|
components: { Todo },
|
|
components: { Todo },
|
|
|
|
+ vuex: {
|
|
|
|
+ state: {
|
|
|
|
+ todos: state => state.todos
|
|
|
|
+ },
|
|
|
|
+ actions: {
|
|
|
|
+ addTodo,
|
|
|
|
+ toggleAll,
|
|
|
|
+ clearCompleted
|
|
|
|
+ }
|
|
|
|
+ },
|
|
data () {
|
|
data () {
|
|
return {
|
|
return {
|
|
visibility: 'all',
|
|
visibility: 'all',
|
|
@@ -63,9 +78,6 @@ export default {
|
|
}
|
|
}
|
|
},
|
|
},
|
|
computed: {
|
|
computed: {
|
|
- todos () {
|
|
|
|
- return this.$store.state.todos
|
|
|
|
- },
|
|
|
|
allChecked () {
|
|
allChecked () {
|
|
return this.todos.every(todo => todo.done)
|
|
return this.todos.every(todo => todo.done)
|
|
},
|
|
},
|
|
@@ -77,18 +89,12 @@ export default {
|
|
}
|
|
}
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
- addTodo (e) {
|
|
|
|
|
|
+ tryAddTodo (e) {
|
|
var text = e.target.value
|
|
var text = e.target.value
|
|
if (text.trim()) {
|
|
if (text.trim()) {
|
|
- this.$store.actions.addTodo(text)
|
|
|
|
|
|
+ this.addTodo(text)
|
|
}
|
|
}
|
|
e.target.value = ''
|
|
e.target.value = ''
|
|
- },
|
|
|
|
- toggleAll () {
|
|
|
|
- this.$store.actions.toggleAll()
|
|
|
|
- },
|
|
|
|
- clearCompleted () {
|
|
|
|
- this.$store.actions.clearCompleted()
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|