2👍
This is because you’re not using fat arrows, change the code to:
methods:{
searchFrom (){
var autoComplete = new google.maps.places.AutocompleteService();
autoComplete.getPlacePredictions({input:this.from}, data => {
this.places=data;
});
}
},
In more details:
when you call autoComplete.getPlacePredictions
it uses a callback, and in that callback the this
context is changed and is no longer Vue context, so it does not know what this.places
is. Fat arrow (=>) takes care of it and makes sure that the context remains the same.
- [Vuejs]-Print both key and value to the console
- [Vuejs]-Order of Props, Computed, and Created in vuejs/vuex
0👍
I’ve never had good luck using fat arrows in Vue. The this is not what you expect. Try explicitly assigning this
at the start of your searchFrom() method, like this…
methods:{
searchFrom (){
var me = this;
var autoComplete = new google.maps.places.AutocompleteService();
autoComplete.getPlacePredictions({me.from}, data => {
me.places=data;
});
}
}
Source:stackexchange.com