提示

本教程基于Vue3 + Ts 开发

使用步骤

按 NPM 方式安装使用 Loader

1
npm i @amap/amap-jsapi-loader --save

创建MyMap.vue文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<template>
<div class="map">
<div id="container"></div>
</div>
</template>
<script setup lang="ts">
import {
onMounted,
reactive,
} from "vue";
import AMapLoader from "@amap/amap-jsapi-loader";
const state = reactive({
map: null,
});
const initMap = () => {
AMapLoader.load({
key: "", // 高德地图秘钥
version: "2.0",
plugins: [],
})
.then((AMap) => {
state.map = new AMap.Map("container", {
viewMode: "3D",
zoom: 18,
center: props.modelValue,
doubleClickZoom: false,
});
})
.catch((e) => {
console.log(e);
});
};

onMounted(() => {
initMap();
});
</script>
<style lang="less" scoped>
#container {
padding: 0px;
margin: 0px;
width: 100%;
height: 100%;
}
</style>