I'm currently exploring how to integrate the Google Maps Javascript
API
into my VueJs
project without relying on the vue2-google-maps package (as it seems too restrictive to me).
Here's what I've done so far, after registering my Vue component
in app.js
:
require('./bootstrap');
window.Vue = require('vue');
const app = new Vue({
el: '#app',
});
Vue.component(
'map-component',
require('./components/MapComponent.vue').default
);
In MapComponent.vue
<template>
<div id="map"></div>
</template>
<script>
export default {
data: function() {
return {
}
},
created() {
let googleApi = document.createElement('script');
googleApi.setAttribute('src', 'https://maps.googleapis.com/maps/api/js?key=AIzaSyA.......S-3SvLw_-twW72Zg&callback='+this.initMap+'');
document.head.appendChild(googleApi);
},
mounted() {
initMap: function() {
var map;
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 8
});
}
},
}
</script>
I've also attempted swapping created()
with mounted()
, but encountered the same error.
The desired outcome, without errors, is to display a Google map on the page.
Thank you for your assistance
Aymeric