[Vuejs]-Handling Google Geocode Callback Results to Vue JS Model

0👍

I was able to get this to work by copying the Vue model into a variable (self).

How can I update a Vue app's or component's property in a promise call back?

checkZip: function () {
    if (this.zipCode.length == 5 && !isNaN(this.zipCode)) {
        var self = this;
        var geocoder = new google.maps.Geocoder();
        geocoder.geocode({ 'address': 'zipcode ' + this.zipCode }, function (results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                self.lat = results[0].geometry.location.lat();
                self.lng = results[0].geometry.location.lng();
                self.refresh();
            } else {
                console.error("Request failed.")
            }
        });
    }
}

Leave a comment