I decided it would be interesting to try and make a Vue app that would use Google Maps. I'm currently displaying markers based on elements in array.
My array starts with 2 default objects so my map displays 2 markers. I then added a button which pushes extra objects, however, these objects do not appear on the map. Vue reactivity is quite new to me so I assume I'm not doing something right.
<template>
<div class="wrapper">
<button @click='addMark'>Add</button>
<GmapMap
:center="center"
:zoom="zoom"
:map-type-id="map"
style="width: 100%; height: 850px"
>
<GmapMarker
v-for="marker in markers"
:position="marker"
:clickable="true"
:draggable="true"
@click="center=marker"
/>
</GmapMap>
</div>
</template>
<script>
export default {
data: function() {
return {
images: [],
markers: [{lat: 42.150527, lng: 24.746477}, {lat: 42.160527, lng: 24.796477}],
center: {lat: 42.150527, lng: 24.746477},
zoom: 15,
map: 'roadmap'
}
},
methods: {
addMark(){
this.markers.push({lat: 42.150529, lng: 24.746479})
console.log(this.markers)
}
}
}
</script>