[Vuejs]-How to call to external function in axios.spread function in VueJS?

2👍

This is a very common mistake. this in userCompInfo doesn’t refer to the Vue because of they way you have written the callback.

In your code, make this change.

userCompInfo:function()
{
    axios.all([this.userInfo(),this.compInfo()])
    .then(axios.spread(function (user, comp){
        // a bunch of code...
    }.bind(this)));
},

Or

userCompInfo:function()
{
    let self = this;
    axios.all([this.userInfo(),this.compInfo()])
    .then(axios.spread(function (user, comp){
        // a bunch of code...
        self.showNotification(...)
        // some more code...
    }));
},

See How to access the correct this inside a callback?

👤Bert

Leave a comment