由于某些原因,我不得不在vue2-google-maps中使用vue2-google-maps,但是我不知道如何开始,因为文档和许多人在HTML部件中使用<GmapMarker ... />。
我试过搜索,但文件没有包括这个。
现在,我的代码看起来是这样的,它没有任何错误,但也不能工作(地图是存在的,但是标记没有显示):
<template>
<div style="height: 100%; width: 100%;">
<GmapMap
:center="{ lat: 0, lng: 0 }"
ref="mapRef"
>
</GmapMap>
</div>
</template><script>
import * as VueGoogleMaps from 'vue2-google-maps';
export default {
computed: {
google: VueGoogleMaps.gmapApi,
},
methods: {
init() {
new this.google.maps.Marker({
position: {
lat: 0,
lng: 0
},
map: this.$refs.mapRef,
});
}
},
async mounted() {
this.init()
},
}
</script>发布于 2019-04-21 10:12:53
好吧,我想出来了。我所做的是:
在data()中创建映射变量
data() {
return {
map: undefined,
}
},在mounted()中使用此函数进行设置
mounted() {
this.$refs.mapRef.$mapPromise.then((map) => {
this.map = map;
this.init();
});
},现在,鲍勃是你的叔叔,你可以在你想要的任何地方使用this.map
methods: {
init() {
new this.google.maps.Marker({
position: {
lat: 0,
lng: 0
},
map: this.map,
});
},
}https://stackoverflow.com/questions/55781690
复制相似问题