google-maps - this.$router.push() 在谷歌地图 place_changed 函数中无法识别
问题描述
我有一个连接到谷歌地图位置自动完成功能的文本框。我调用了新的google.maps.places.Autocomplete()
内部 vue 安装属性。根据搜索结果,我想将我的页面重定向到调用 this.$router.push() 函数的搜索过滤器页面。但我不知道为什么this.$router.push()
在 google map 内部无法识别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;
});
解决方案
如果你想保留你的代码,你可以在你的函数中添加它。
让 $this = 这个
但它似乎又脏又旧,最好将函数更改为 ()=>
推荐阅读
- java - 在 JSON 数组中查找 JSON 对象
- amazon-web-services - 在部署期间无法获取 cloudformation 模板来安装应用程序
- python - 为什么我的代码总是给出相同的结果,即“字符串不是回文”
- mysql - 如何正确设置备份文件
- python - 我想将我的文本文件逐字而不是逐行放入数组中
- express - Mongoose 和 ref UUID 数组不转换
- php - cli 和 PHP 上的相同 MySQL 转储命令返回不同
- apache - 将每个子域重定向到单个目录
- react-native - 与 react-navigator 3 混淆 react-navigation
- javascript - 如何允许在可点击的 div 容器上选择和复制文本?