File tree Expand file tree Collapse file tree 3 files changed +19
-23
lines changed Expand file tree Collapse file tree 3 files changed +19
-23
lines changed Original file line number Diff line number Diff line change 46
46
</template >
47
47
48
48
<script >
49
- import store from ' ../store'
50
49
import Todo from ' ./Todo.vue'
51
50
52
- const {
53
- addTodo ,
54
- toggleAll ,
55
- clearCompleted
56
- } = store .actions
57
-
58
51
const filters = {
59
52
all : (todos ) => todos,
60
53
active : (todos ) => todos .filter (todo => ! todo .done ),
@@ -71,7 +64,7 @@ export default {
71
64
},
72
65
computed: {
73
66
todos () {
74
- return store .state .todos
67
+ return this . $ store .state .todos
75
68
},
76
69
allChecked () {
77
70
return this .todos .every (todo => todo .done )
@@ -87,12 +80,16 @@ export default {
87
80
addTodo (e ) {
88
81
var text = e .target .value
89
82
if (text .trim ()) {
90
- addTodo (text)
83
+ this . $store . actions . addTodo (text)
91
84
}
92
85
e .target .value = ' '
93
86
},
94
- toggleAll,
95
- clearCompleted
87
+ toggleAll () {
88
+ this .$store .actions .toggleAll ()
89
+ },
90
+ clearCompleted () {
91
+ this .$store .actions .clearCompleted ()
92
+ }
96
93
}
97
94
}
98
95
</script >
Original file line number Diff line number Diff line change 19
19
</template >
20
20
21
21
<script >
22
- import store from ' ../store'
23
- const {
24
- toggleTodo ,
25
- deleteTodo ,
26
- editTodo
27
- } = store .actions
28
-
29
22
export default {
30
23
props: [' todo' ],
31
24
data () {
@@ -43,14 +36,18 @@ export default {
43
36
}
44
37
},
45
38
methods: {
46
- toggleTodo,
47
- deleteTodo,
39
+ toggleTodo (todo ) {
40
+ this .$store .actions .toggleTodo (todo)
41
+ },
42
+ deleteTodo (todo ) {
43
+ this .$store .actions .deleteTodo (todo)
44
+ },
48
45
doneEdit (e ) {
49
- var value = e .target .value .trim ()
46
+ const value = e .target .value .trim ()
50
47
if (! value) {
51
- deleteTodo (this .todo )
48
+ this . deleteTodo (this .todo )
52
49
} else if (this .editing ) {
53
- editTodo (this .todo , value)
50
+ this . editTodo (this .todo , value)
54
51
this .editing = false
55
52
}
56
53
},
Original file line number Diff line number Diff line change 1
1
import Vue from 'vue'
2
+ import store from './store'
2
3
import App from './components/App.vue'
3
4
4
5
new Vue ( {
6
+ store, // inject store to all children
5
7
el : 'body' ,
6
8
components : { App }
7
9
} )
You can’t perform that action at this time.
0 commit comments