MapComponent.vue
842 Bytes
<script lang="ts" setup>
import { nextTick, onMounted, ref, unref } from 'vue';
import { useScript } from '/@/hooks/web/useScript';
import { BAI_DU_MAP_URL } from '/@/utils/fnUtils';
const wrapRef = ref<HTMLDivElement | null>(null);
const { toPromise } = useScript({ src: BAI_DU_MAP_URL });
async function initMap() {
await toPromise();
await nextTick();
const wrapEl = unref(wrapRef);
if (!wrapEl) return;
const BMap = (window as any).BMap;
const map = new BMap.Map(wrapEl);
const point = new BMap.Point(116.404, 39.915);
map.centerAndZoom(point, 15);
map.enableScrollWheelZoom(true);
}
onMounted(() => {
initMap();
});
</script>
<template>
<div class="w-full h-full flex justify-center items-center">
<div ref="wrapRef" class="w-[95%] h-[95%]"></div>
</div>
</template>