美文网首页嵌牛IT观察
Vue2.0与 [百度地图] 结合使用:

Vue2.0与 [百度地图] 结合使用:

作者: 丘之心 | 来源:发表于2017-12-15 11:06 被阅读0次

姓名:岳沁

学号:17101223458

转载自:http://www.cnblogs.com/yufann/p/Vue-Node9.html

【嵌牛导读】:

Vue2.0与 [百度地图] 结合使用

【嵌牛鼻子】:thymeleaf

【嵌牛提问】:如何解决Map未定义?

【嵌牛正文】:

Vue2.0与 [百度地图] 结合使用:

1.vue init webpack-simple vue-baidu-map

2.下载axios

cnpm install axios;

3.在main.js中引入axios,并使用

import axios from 'axios'

/* 把axios对象挂到Vue实例上面,其他组件在使用axios的时候直接 this.$http就可以了 */

Vue.prototype.$http = axios;

4.引入百度地图的js秘钥--->最好在index.js中直接引入

5.新建文件Map.vue,作为map组件使用

export default{

data:(){

return{

style:{

width:'100%',

height:this.height+'px'

}

}

},

props:{ //里面存放的也是数据,与data里面的数据不同的是,这里的数据是从其他地方得到的数据

height:{

type:Number,

default:300

},

longitude:{}, //定义经度

latitude:{} //定义纬度

},

mounted(){

var map = new BMap.Map("div1");

var point = new BMap.Point(this.longitude,this.latitude);

map.centerAndZoom(point, 12);

var marker = new BMap.Marker(point);// 创建标注

map.addOverlay(marker);

}

}

6.假如最终组件在App.vue里面使用

import MapView from './components/Map.vue'

export default{

data(){

return{

height:300,

longitude:116.404,

latitude:39.915

}

},

componets:{

MapView

},

mounted(){

}

}

相关文章

网友评论

    本文标题:Vue2.0与 [百度地图] 结合使用:

    本文链接:https://www.haomeiwen.com/subject/dumrwxtx.html