浅谈vue方法内的方法使用this的问题
如下所示:
locapos(){//定位方法
if(navigator.geolocation){ navigator.geolocation.getCurrentPosition(function(position){ varpos={ lat:position.coords.latitude, lng:position.coords.longitude }; varlatLng=newgoogle.maps.LatLng(aa[1], aa[0]); varinfoWindow=newgoogle.maps.InfoWindow({ content:"当前位置:
经度:"+pos.lat+"
维度:"+pos.lng //提示窗体内的提示信息 }); infoWindow.setPosition(latLng); _this.mark=newgoogle.maps.Marker({ position:latLng,//将前面设定的坐标标注出来 icon:image, animation:google.maps.Animation.BOUNCE,//添加动画效果 map:map//将该标注设置在刚才创建的map中 }); ////标注提示窗口 ////打开提示窗口 infoWindow.open(map,mark); },function(){ handleLocationError(true,infoWindow,map.getCenter()); }); }else{ //Browserdoesn'tsupportGeolocation handleLocationError(false,infoWindow,map.getCenter()); }
methods中定义一个locapos()定位方法,其中想在内部方法中使用this调用data()中定义的marker一致不成功,提示未定义,经过不懈努力终于找到解决方法,增加一句话就OK了!
var_this=this;
如此简单,豁然开朗!
以上这篇浅谈vue方法内的方法使用this的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。