引入是lazyAMapApiLoaderInstance必须在VueAMap.initAMapApiLoader的后面,否者会报错:
vue.runtime.esm.js?a593:619 [Vue warn]: Error in created hook: “TypeError: Cannot read property ‘load’ of null”

解决办法:lazyAMapApiLoaderInstance放VueAMap.initAMapApiLoader的后面
created () {
console.log('map created')
VueAMap.initAMapApiLoader({
key: '2ae1af475671e2cbca546261047e2264',
plugin: [
'AMap.Autocomplete',
'AMap.PlaceSearch',
'AMap.Scale',
'AMap.OverView',
'AMap.ToolBar',
'AMap.MapType',
'AMap.PolyEditor',
'AMap.CircleEditor',
'AMap.Geolocation'
]
})
lazyAMapApiLoaderInstance.load().then(() => {
console.log('map loaded')
const geolocation = new AMap.Geolocation({
enableHighAccuracy: true,
timeout: 6000,
maximumAge: 0,
convert: true,
showButton: true,
buttonPosition: 'LB',
buttonOffset: new AMap.Pixel(10, 20),
showMarker: true,
showCircle: true,
panToLocation: true,
zoomToAccuracy: true
})
console.log(geolocation)
geolocation.getCurrentPosition()
AMap.event.addListener(geolocation, 'complete', this.onComplete)
AMap.event.addListener(geolocation, 'error', this.onError)
})
}