-1👍
✅
The scope of this
change inside getJSON function.
You must save the parent this
var url ="http://api.apixu.com/v1/current.json?key=a69259fba9904700964121622190801&q=Nazilli";
var me = this; // save this in me variable
$.getJSON(url,function(json){
console.log(json);
me.isLoading = false;
me.Country = json.location.name; // use me instead this
console.log(me.Country);
});
1👍
You’re losing this
context in $.getJSON
callback: it doesn’t point to Vue instance inside function call.
You should ether bind this
to function directly:
$.getJSON(url, (function (json) {
//...
}).bind(this));
Or use fat arrow function:
$.getJSON(url, (json) => {
//...
});
Source:stackexchange.com