this。$ router.push()无法在Google Map place_changed函数中识别

时间:2019-08-28 02:43:52

标签: google-maps laravel-5 vuejs2

我有一个与Google Map Place Place自动完成功能连接的文本框。我将新的google.maps.places.Autocomplete()称为vue Mounted属性。根据搜索结果,我想将页面重定向到调用this。$ router.push()函数的搜索过滤器页面。但是我不知道为什么this.$router.push()无法在Google地图place_changed()内部识别。

我在this.$router.push()内部给mounted(){}打了电话。它工作正常,但我需要在this.$router.push()内部识别place_changed()

<input id="modal-filters-Main"
                                        placeholder="Enter an address, neighborhood, city or ZIP code"
                                        class="typeahead form-control form-ready-for-bubble" >

var SearchBox = new google.maps.places.Autocomplete(document.getElementById('modal-filters-Main'));
            SearchBox.addListener('place_changed', function() {
                 this.place = SearchBox.getPlace();
                 this.formatter = this.place.formatted_address;
                 this.lower = this.formatter.toLowerCase();
                 this.modified = this.lower.replace(", ","_");
                this.$router.push('/listing/'+this.modified);
                // window.location.href = '/listing/'+modified;
            });

1 个答案:

答案 0 :(得分:0)

如果要保留代码,可以将其添加到函数中。

让$ this =此

但似乎又脏又旧,最好将函数更改为()=>