如下所示:
locapos(){//定位方法
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
var latLng = new google.maps.LatLng(aa[1],
aa[0]);
var infoWindow = new google.maps.InfoWindow({
content: "当前位置:<br/>经度:" + pos.lat + "<br/>维度:" + pos.lng
//提示窗体内的提示信息
});
infoWindow.setPosition(latLng);
_this.mark = new google.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 {
// Browser doesn't support Geolocation
handleLocationError(false, infoWindow, map.getCenter());
}
methods中定义一个locapos()定位方法,其中想在内部方法中使用this调用data()中定义的marker一致不成功,提示未定义,经过不懈努力终于找到解决方法,增加一句话就OK了!
var _this = this;
如此简单,豁然开朗!
以上这篇浅谈vue方法内的方法使用this的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持亿速云。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。