vue 百度地图开发【教程】1. 绘制百度地图(不使用 vue-baidu-map,解决 BMap is undefined)

简介: vue 百度地图开发【教程】1. 绘制百度地图(不使用 vue-baidu-map,解决 BMap is undefined)

1. 在 public/index.html 中引入百度地图

  <!--引入百度地图-->
  <script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=你的百度ak"></script>

2. 在 vue.config.js 中配置 BMap

module.exports = {
    configureWebpack: {
        externals: {
            "BMap": "BMap",
        },
    },
}

3. 在 .vue 文件中引入 BMap

import BMap from 'BMap'

4. 在 .vue 文件中绘制地图

<div id="myMap" style="height: 400px"></div>
mounted(){
    var map = new BMap.Map("myMap");  // 创建Map实例
    map.centerAndZoom("上海",15);      // 初始化地图,用城市名设置地图中心点
},
目录
打赏
0
0
0
0
63
分享
相关文章
|
5月前
|
vue尚品汇商城项目-day07【52.打包文件,处理map文件】
vue尚品汇商城项目-day07【52.打包文件,处理map文件】
33 3
Vue2使用百度地图展示或搜索地点(vue-baidu-map)
本文介绍了如何在 Vue 项目中使用 `vue-baidu-map` 插件,包括安装、全局注册及具体应用。首先通过 `yarn add vue-baidu-map` 安装插件,并在 `main.js` 中全局注册。然后展示了如何在地图上显示特定位置的标记,以及如何搜索地点并获取其经纬度和详细地址信息。代码示例提供了详细的实现方法和样式调整。如需使用,请确保已获取百度地图 API 的密钥。
996 1
Vue 系类之 this.tabledatas.map 无效
这篇文章讲述了在Vue项目中使用`this.tabledatas.map`处理接口返回的数组数据时遇到的问题,原因是由于取错了后端返回的数据集合字段值,导致`.map`方法无效,通过检查和修正数据取值解决了问题。
Vue 系类之 this.tabledatas.map 无效
Vue中传递自定义参数到后端、后端获取数据(使用Map接收参数)
这篇文章讲述了如何在Vue中通过Axios二次封装传递自定义参数到后端,并展示了后端如何使用Map接收这些参数,以及如何避免参数转换错误和统一接口设计的方法。
Golang 开发函数计算问题之在 Golang 中避免 "concurrent map writes" 异常如何解决
Golang 开发函数计算问题之在 Golang 中避免 "concurrent map writes" 异常如何解决
109 0
|
7月前
|
VUE——filemanager-webpack-plugin报错TypeError: Cannot read property 'isFile' of undefined
VUE——filemanager-webpack-plugin报错TypeError: Cannot read property 'isFile' of undefined
135 0
VUE——Uncaught (in promise) TypeError: Cannot read property '__esModule' of undefined
VUE——Uncaught (in promise) TypeError: Cannot read property '__esModule' of undefined
149 0
成功解决:Cannot read properties of undefined (reading ‘commit‘)
这篇文章提供了解决Vuex中"Cannot read properties of undefined (reading 'commit')"错误的两种方法:检查模板中的数据属性是否存在,以及确保在Vue实例中正确挂载了store对象。
成功解决:Cannot read properties of undefined (reading ‘commit‘)
Echarts——Invalid geoJson format Cannot read property 'length' of undefined
Echarts——Invalid geoJson format Cannot read property 'length' of undefined
134 0
TypeError: Cannot set properties of undefined (setting ‘resdata‘),res定义数据出现的问题,定义的方法用this换成that
TypeError: Cannot set properties of undefined (setting ‘resdata‘),res定义数据出现的问题,定义的方法用this换成that

热门文章

最新文章

AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等