File tree Expand file tree Collapse file tree 1 file changed +23
-20
lines changed
Expand file tree Collapse file tree 1 file changed +23
-20
lines changed Original file line number Diff line number Diff line change 2525 // the root element that will be compiled
2626 el : '.todoapp' ,
2727
28- // app state data
28+ // app initial state
2929 data : {
3030 todos : todoStorage . fetch ( ) ,
3131 newTodo : '' ,
3232 editedTodo : null ,
3333 visibility : 'all'
3434 } ,
3535
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
5543 }
5644 } ,
5745
117105 removeCompleted : function ( ) {
118106 this . todos = filters . active ( this . todos ) ;
119107 }
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+ }
120123 }
121124 } ) ;
122125
You can’t perform that action at this time.
0 commit comments