浅谈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的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
热门推荐
10 香港老妈结婚祝福语简短
11 毕业立体贺卡祝福语简短
12 简短新年年会祝福语
13 评论小品祝福语大全简短
14 恭喜师兄结婚祝福语简短
15 员工集体辞职祝福语简短
16 高中新生祝福语 简短
17 装修祝福语男生搞笑简短
18 生日开业蛋糕祝福语简短