npm安装@amap/amap-jsapi-loader包
<script setup>
import AMapLoader from '@amap/amap-jsapi-loader';
import { shallowRef } from '@vue/reactivity';
const allMap = shallowRef(null);
function initMap() {
window._AMapSecurityConfig = {
securityJsCode: '密钥',
}
AMapLoader.load({
key: "key",
version: "2.0",
plugins: ["AMap.GeoJSON"],
}).then((AMap) => {
const map = new AMap.Map("container", {
viewMode: "2D",
zoom: 10,
center: [119.898881, 30.594178],
mapStyle: 'amap://styles/...',
});
allMap.value = map
});
}).catch(e => {
console.log(e);
})
}
initMap()
</script>