自动完成侦听器更改Vue数据

时间:2019-08-28 13:01:02

标签: vue.js

我有以下代码:

data() {
   return {
      markers: [],
   };
},

methods: {
   var partidaAutoComplete = new window.google.maps.places.Autocomplete(document.getElementById("partida"));
   partidaAutoComplete.addListener("place_changed", function() {
      var place = partidaAutoComplete.getPlace();
      var partidaLatLng = new window.google.maps.LatLng(
        place.geometry.location.lat(),
        place.geometry.location.lng()
      );
      var marker = new window.google.maps.Marker({ position: partidaLatLng });
      this.markers.push(marker);
   });
}

当我尝试将标记插入数据变量标记时,控制台会向我显示此错误:

Uncaught TypeError: Cannot read property 'push' of undefined

我知道这是一个异步方法,但是如何检索侦听器标记并将其分配到我的组件中

0 个答案:

没有答案