0👍
You’ve got a misplaced )
. .bind()
needs to be called on the function directly, in this case on the }
:
this.$http.get('/me', function(resp){
this.userDetails = resp.data;
}.bind(this));
- [Vuejs]-Vue JS 2 Data Object Changes However Method Doesn't Run
- [Vuejs]-Passing a (timestamp) as an argument for a REST GET API
0👍
This worked:
new Vue({
el : 'body',
data : {
projects: [],
userDetails: {},
},
created : function(){
this.fetchMyUserDetails();
// this.fetchMyProjects(); // Needed to chain it into fetchMyUserDetails()
},
methods : {
fetchMyUserDetails : function(){
this.$http.get('/me', function(resp){
this.userDetails = resp.data;
this.fetchMyProjects(); // Works!
}).bind(this);
},
fetchMyProjects: function(){
this.$http.get('/projects/user/' + this.userDetails.id, function(projects){
this.projects = projects.data;
}).bind(this);
},
}
});
Source:stackexchange.com