File tree 1 file changed +23
-20
lines changed
1 file changed +23
-20
lines changed Original file line number Diff line number Diff line change 25
25
// the root element that will be compiled
26
26
el : '.todoapp' ,
27
27
28
- // app state data
28
+ // app initial state
29
29
data : {
30
30
todos : todoStorage . fetch ( ) ,
31
31
newTodo : '' ,
32
32
editedTodo : null ,
33
33
visibility : 'all'
34
34
} ,
35
35
36
- // ready hook, watch todos change for data persistence
37
- ready : function ( ) {
38
- this . $watch ( 'todos' , function ( todos ) {
39
- todoStorage . save ( todos ) ;
40
- } , { deep : true } ) ;
41
- } ,
42
-
43
- // a custom directive to wait for the DOM to be updated
44
- // before focusing on the input field.
45
- // http://vuejs.org/guide/directives.html#Writing_a_Custom_Directive
46
- directives : {
47
- 'todo-focus' : function ( value ) {
48
- if ( ! value ) {
49
- return ;
50
- }
51
- var el = this . el ;
52
- setTimeout ( function ( ) {
53
- el . focus ( ) ;
54
- } , 0 ) ;
36
+ // watch todos change for localStorage persistence
37
+ watch : {
38
+ todos : {
39
+ handler : function ( todos ) {
40
+ todoStorage . save ( todos ) ;
41
+ } ,
42
+ deep : true
55
43
}
56
44
} ,
57
45
117
105
removeCompleted : function ( ) {
118
106
this . todos = filters . active ( this . todos ) ;
119
107
}
108
+ } ,
109
+
110
+ // a custom directive to wait for the DOM to be updated
111
+ // before focusing on the input field.
112
+ // http://vuejs.org/guide/custom-directive.html
113
+ directives : {
114
+ 'todo-focus' : function ( value ) {
115
+ if ( ! value ) {
116
+ return ;
117
+ }
118
+ var el = this . el ;
119
+ Vue . nextTick ( function ( ) {
120
+ el . focus ( ) ;
121
+ } ) ;
122
+ }
120
123
}
121
124
} ) ;
122
125
You can’t perform that action at this time.
0 commit comments