1. 最终效果
2. 申请百度地图秘钥
https://blog.csdn.net/weixin_42813606/article/details/88556804
3. 代码
(1)定义
地图组件:map.vue(重要的2个参数:中心点坐标和秘钥)
<template>
<!-- 这是地图组价, 是一个公共的组件 -->
<div
:id="id"
:style="{width:width+'px',height:height+'px',margin:'34px auto'}"
class="m-map"/>
</template>
<script>
export default {
props: {
width: {
type:Number,
default:300
},
height: {
type:Number,
default:300
},
// 中心点
point: {
type:Array,
default(){
return [116.46,39.92] // 1.中心点坐标(百度可查任意城市坐标)
}
}
},
data() {
return {
id