1、nuxt.conig.ts中创建script标签,引入地图组件
script: [
{
type: 'text/javascript',
src:'https://webapi.amap.com/maps?v=2.0&key=*********&plugin=AMap.Geolocation,AMap.Geocoder',
}
]
2、 页面中使用高德地图
<template>
<div id="map-box"></div>
</template>
<script setup lang="ts">
import "@amap/amap-jsapi-types";
// 地图对象
const map = shallowRef<AMap.Map>()
// 加载地图文件
onMounted(() => {
map.value = new AMap.Map('map-box',{
zoom: 11,
center: [116.397428, 39.90923]
});
map.value.on('complete', async () => {
// TODO
})
})
</script>
<style scoped>
#map-box {
width: 100%;
height: 700px;
}
</style>