Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js vuejs这在我的eventListner中未定义_Vue.js - Fatal编程技术网

Vue.js vuejs这在我的eventListner中未定义

Vue.js vuejs这在我的eventListner中未定义,vue.js,Vue.js,我尝试在vuejs中制作一个google地图,地图中心的值显示在我的视图中 为此,我创建了我的标记,并尝试使用this.marker=map.center.lng()更新该值或this.setmarkerng(map.center.lng())在我的方法Initmap的事件列表器中,但它们都不起作用。我得到了信息: 这是未定义的 在eventlistener之外,一切都正常 你能帮忙吗 export default { mounted: function () {

我尝试在vuejs中制作一个google地图,地图中心的值显示在我的视图中

为此,我创建了我的标记,并尝试使用
this.marker=map.center.lng()更新该值
this.setmarkerng(map.center.lng())在我的方法Initmap的事件列表器中,但它们都不起作用。我得到了信息:

这是未定义的

在eventlistener之外,一切都正常

你能帮忙吗

export default {
        mounted: function () {
            this.initMap();
        },
        data() {
            return {
                marker: {
                    lng : 'latitude',
                    lat: 'longitude'
                        }
            }
        },
        methods: {
            ///google map init
            initMap() {
                var map = new google.maps.Map(document.getElementById('map'), {
                    center: {lat: 48.587536, lng: 7.751440},
                    zoom: 13
                });

                this.setMarkerLat(map.center.lat());
                this.setMarkerLng(map.center.lng());

                ///Listner
                autocomplete.addListener('place_changed', function () {

                    ///call method bug
                    this.setMarkerLat(map.center.lat());
                    this.setMarkerLng(map.center.lng());

                    infowindow.close();
                      this.marker.lat = map.center.lat();
                      this.marker.lng = map.center.lng();
                    marker.setVisible(false);
                    var place = autocomplete.getPlace();
                    if (!place.geometry) {

                        window.alert("No details available for input: '" + place.name + "'");
                        return;
                    }

                    // If the place has a geometry, then present it on a map.
                    if (place.geometry.viewport) {
                        map.fitBounds(place.geometry.viewport);
                    } else {
                        map.setCenter(place.geometry.location);
                        map.setZoom(17);  // Why 17? Because it looks good.
                    }
                    marker.setPosition(place.geometry.location);
                    marker.setVisible(true);


                    var address = '';
                    if (place.address_components) {
                        address = [
                            (place.address_components[0] && place.address_components[0].short_name || ''),
                            (place.address_components[1] && place.address_components[1].short_name || ''),
                            (place.address_components[2] && place.address_components[2].short_name || '')
                        ].join(' ');
                    }
            },
            setMarkerLng: function(lng) {
                this.marker.lng = lng;
            },
            setMarkerLat: function(lat){
                this.marker.lat = lat;
            }
        }
    }

尝试使用箭头功能
()=>
,以便能够访问
此范围,如:

autocomplete.addListener('place_changed', ()=> {
  ...
 }

尝试使用箭头功能
()=>
,以便能够访问
此范围,如:

autocomplete.addListener('place_changed', ()=> {
  ...
 }

非常感谢!!因此,如果我想确定vue对象的范围,我需要使用arrow?是的,或者您应该将
分配给一个全局变量,并在回调函数中访问该变量谢谢!!因此,如果我想确定vue对象的范围,我需要使用arrow?是的,或者您应该将
分配给一个全局变量,并在回调函数中访问该变量尝试将
自动完成
值绑定到某个属性,如
位置
,然后观看这个道具并分派你放在
place\u changed
事件中的函数。将
place\u changed
事件中执行的代码移动到“place
prop
更改”时将调用的方法。尝试将
autocomplete
值绑定到某个prop,如
place
,然后观看此prop并分派放置在
place\u changed
事件中的函数。将
place\u changed
事件中执行的代码移动到一个方法中,该方法将在`place
prop
change'时调用。