如下所示:
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: "當(dāng)前位置:<br/>經(jīng)度:" + pos.lat + "<br/>維度:" + pos.lng      //提示窗體內(nèi)的提示信息     });    infoWindow.setPosition(latLng);     _this.mark = new google.maps.Marker({      position: latLng, //將前面設(shè)定的坐標(biāo)標(biāo)注出來(lái)      icon:image,      animation: google.maps.Animation.BOUNCE,//添加動(dòng)畫效果      map: map //將該標(biāo)注設(shè)置在剛才創(chuàng)建的map中     });  //    //標(biāo)注提示窗口   //    //打開(kāi)提示窗口     infoWindow.open(map, mark);    }, function() {    handleLocationError(true, infoWindow, map.getCenter());   });   } else {   // Browser doesn't support Geolocation   handleLocationError(false, infoWindow, map.getCenter());   }methods中定義一個(gè)locapos()定位方法,其中想在內(nèi)部方法中使用this調(diào)用data()中定義的marker一致不成功,提示未定義,經(jīng)過(guò)不懈努力終于找到解決方法,增加一句話就OK了!
var _this = this;
如此簡(jiǎn)單,豁然開(kāi)朗!
以上這篇淺談vue方法內(nèi)的方法使用this的問(wèn)題就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持錯(cuò)新站長(zhǎng)站。
新聞熱點(diǎn)
疑難解答
圖片精選