[Vuejs]-Passing vue-resource AJAX data around

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));

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);

    },


}

});

Leave a comment