【发布时间】:2019-02-18 21:27:49
【问题描述】:
我已经编写了制作谷歌地图的自定义指令。
Vue.directive('gmap', {
inserted: function (el) {
return new google.maps.Map(el, {
center: { lat: -34.397, lng: 150.644 },
zoom: 8
})
}
})
<div v-gmap ref="map" style="height: 360px"></div>
它有效,我可以看到地图。
然后,我想在地图上画一个标记,并且需要一个谷歌地图对象。
我可以从 v-gmap 指令中获取返回值吗?
mounted () {
const map = this.$refs.map
const marker = new google.maps.Marker({
position: { lat: -34.397, lng: 150.644 },
map: map,
title: 'Hello World!'
});
}
它不起作用。
map 只是 HTML 元素..
【问题讨论】:
标签: vue.js vue-directives