第一步,去百度地圖開發(fā)者申請秘鑰。
第二步在項目中引入,具體如下

其中index.html存放地圖鏈接,代碼如下

然后在APP.vue里面實現(xiàn),代碼如下
<template> <div id="app"> <div id="allmap" ref="allmap"></div> <router-view></router-view> </div></template> <script>export default { name: 'App', methods:{ map(){ let map =new BMap.Map(this.$refs.allmap); // 創(chuàng)建Map實例 map.centerAndZoom(new BMap.Point(116.404, 39.915), 11);// 初始化地圖,設置中心點坐標和地圖級別 map.addControl(new BMap.MapTypeControl({//添加地圖類型控件 mapTypes:[ BMAP_NORMAL_MAP, BMAP_HYBRID_MAP ]})); map.setCurrentCity("北京");// 設置地圖顯示的城市 此項是必須設置的 map.enableScrollWheelZoom(true); //開啟鼠標滾輪縮放 } }, mounted(){ this.map() }}</script> <style>#app { font-family: 'Avenir', Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-align: center; color: #2c3e50; margin-top: 60px;}#allmap{ height: 500px; overflow: hidden; }</style>以上所述是小編給大家介紹的vue在項目中使用百度地圖詳解整合,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網(wǎng)網(wǎng)站的支持!
新聞熱點
疑難解答