}The
}The
});
View = new view ({
50: \
Data: {}
});
});
}) (J query);
Male
Male male
Male male
It is very similar to the last time, but there is no loop. It is a separate component. Improve components for reuse, so far, to simplify jQuery. These components are created inside the components of get (). Get posts or posts and use them to create components. Work, but components are strongly connected to HTTP requests and are difficult to reuse. Therefore, we want to discuss the initial life cycle of the component and how to move Ajax calls inside the component. This will delay loading components and can be reused in the next part of the series. If a method is loaded when the component is loaded, the method is called. This is a method to call a function from the methods property of a component or elsewhere and import data from the WordPress rest API. The following is the new post event list component: Vue Component (\
Template: \post-list-tmpl
Data: functions (){
Returns
List: in fact,
Display: 0,
Post: []
}The
},
Loading: functions (){
This Getposts();
},
Method:{
Getposts: function (){
Var porcelain = this;
$ Get (config.api.posts, function (R){
Self$ Set (self,’posts’, R);
});
},
Read: function (ID){
This List= false;
This Show=id;
},
Closing: functions (){
This List= true;
This Show = 0;
}The
}The
}); Note that although the post data is still valuable, it is empty. Otherwise, it will not be considered as a reaction property of the component and cannot be updated later. Other important things to pay attention to are $. Update the value this. in the successful callback of get()$ Use set (). Where’s next? This is how vuejs is used to create reusable components. There are now list views and single views. They are not strongly linked to any API query, so we can use them with other post types, or at least provide data in a single page load without Ajax. We are very close to everything a beginner needs to use a single page web word press theme. Next week, you can learn more about the vuejs router. It will become more and more interesting to switch between paths without loading new pages. Next week, we will connect these two components to the router to build a more complete application. To learn more about the rest API JavaScript framework, see caldera learn.