今天尝试用Vue调用百度地图的api,看了很多文章没有讲的清楚的。尝试了一下,总算成功了,下面是html:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Hello, World</title>
<style type="text/css">
html{height:100%}
body{height:100%;margin:0px;padding:0px}
#map{height:600px;width:1000px}
</style>
<link rel="stylesheet" href="../css/lib/bootstrap.min.css">
<link rel="stylesheet" href="../css/history/dailyweather.css">
<script src="../js/lib/vue.js" type="text/javascript"> </script>
</head>
<body>
<div id="mapproject">
<div id="map">
</div>
</div>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0&ak=你的密钥"></script>
<script type="text/javascript" src="../js/map.js"></script>
</body>
</html>
map.js中的内容
var vm=new Vue(
{
el:'#mapproject',
mounted:function(){
this.BaiduMap();
},
methods:
{
BaiduMap:function(){
var map = new BMap.Map("map");
// 创建地图实例
var point = new BMap.Point(113.34, 22.14);
// 创建点坐标
map.centerAndZoom(point, 12);
}
}
}
)