浅谈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的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下