[Vuejs]-Vue – Cannot set property of undefined in response

5👍

It’s because you are not binding this in the callback of your http call. You could use an arrow function for example to solve it.

from

 .then(function(res) { 
    console.log(res.data.address); // This returns the address
    alert(res.data.address);
    this.address=res.data.address;
 })

to

 .then((res) => { 
    console.log(res.data.address); // This returns the address
    alert(res.data.address);
    this.address=res.data.address;
 })

Leave a comment