在vue单页应用中,百度地图的ak认证获取需放在index.html
的head
里,否则地图将显示不出来。
index.html
<head>
<meta charset="utf-8">
<script type="text/javascript" src="https://api.map.baidu.com/api?v=3.0&ak=S4KKfPTez9LKGm4DtoY2BQ5527qxQ3QE"></script>
</head>
helloWorld.vue
<template>
<div id="map"></div>
</template>
<script>
import echarts from 'echarts'
import 'echarts/extension/bmap/bmap'
export default {
name: 'SMap',
data () {
return {
list:[],
myChart: null
}
},
mounted(){
// 基于准备好的dom,初始化echarts实例
this.myChart = echarts.init(document.getElementById('map'));
// 指定图表的配置项和数据
var option = {
bmap: {
center: [108.114129, 34.550339],