File tree Expand file tree Collapse file tree 3 files changed +9
-16
lines changed Expand file tree Collapse file tree 3 files changed +9
-16
lines changed Original file line number Diff line number Diff line change @@ -39,7 +39,6 @@ <h1>todos</h1>
39
39
class ="toggle "
40
40
type ="checkbox "
41
41
v-model ="completed "
42
- v-on ="change: toggleTodo(this) "
43
42
>
44
43
< label v-text ="title " v-on ="dblclick: editTodo(this) "> </ label >
45
44
< button class ="destroy " v-on ="click: removeTodo(this) "> </ button >
Original file line number Diff line number Diff line change 29
29
filter : 'all'
30
30
} ,
31
31
32
+ // ready hook, watch todos change for data persistence
33
+ ready : function ( ) {
34
+ this . $watch ( 'todos' , function ( todos ) {
35
+ todoStorage . save ( todos ) ;
36
+ } ) ;
37
+ } ,
38
+
32
39
// a custom directive to wait for the DOM to be updated
33
40
// before focusing on the input field.
34
41
// http://vuejs.org/guide/directives.html#Writing_a_Custom_Directive
64
71
this . todos . forEach ( function ( todo ) {
65
72
todo . completed = value ;
66
73
} ) ;
67
- todoStorage . save ( ) ;
68
74
}
69
75
}
70
76
} ,
80
86
}
81
87
this . todos . push ( { title : value , completed : false } ) ;
82
88
this . newTodo = '' ;
83
- todoStorage . save ( ) ;
84
89
} ,
85
90
86
91
removeTodo : function ( todo ) {
87
92
this . todos . $remove ( todo . $data ) ;
88
- todoStorage . save ( ) ;
89
- } ,
90
-
91
- toggleTodo : function ( todo ) {
92
- todoStorage . save ( ) ;
93
93
} ,
94
94
95
95
editTodo : function ( todo ) {
106
106
if ( ! todo . title ) {
107
107
this . removeTodo ( todo ) ;
108
108
}
109
- todoStorage . save ( ) ;
110
109
} ,
111
110
112
111
cancelEdit : function ( todo ) {
116
115
117
116
removeCompleted : function ( ) {
118
117
this . todos = this . todos . filter ( filters . active ) ;
119
- todoStorage . save ( ) ;
120
118
}
121
119
}
122
120
} ) ;
Original file line number Diff line number Diff line change 5
5
'use strict' ;
6
6
7
7
var STORAGE_KEY = 'todos-vuejs' ;
8
- var todos = null ;
9
8
10
9
exports . todoStorage = {
11
10
fetch : function ( ) {
12
- if ( ! todos ) {
13
- todos = JSON . parse ( localStorage . getItem ( STORAGE_KEY ) || '[]' ) ;
14
- }
15
- return todos ;
11
+ return JSON . parse ( localStorage . getItem ( STORAGE_KEY ) || '[]' ) ;
16
12
} ,
17
- save : function ( ) {
13
+ save : function ( todos ) {
18
14
localStorage . setItem ( STORAGE_KEY , JSON . stringify ( todos ) ) ;
19
15
}
20
16
} ;
You can’t perform that action at this time.
0 commit comments