如下所示:
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的問題就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。