nuxt-google-maps-module
nuxt-google-maps-module copied to clipboard
Following the short example runs code before script is loaded.
Am I doing something wrong? I followed the short example, but when I have something on mounted(), it says google is undefined. When I put it on a function I can execute (seconds after the page loads), it works fine. Considering how I followed the short example exactly, I'm assuming something changed, either with Nuxt or with Google Maps API. Can anyone replicate, and is there a fix?
Using the same trick he did in the plugin: https://github.com/WilliamDASILVA/nuxt-google-maps-module/blob/master/src/plugin.template.js#L18
mounted() {
const that = this;
const event = new window.Event('maps-module:initiated');
window.dispatchEvent(event);
window.addEventListener('maps-module:loaded', () => {
that.initGoogleApi();
});
},
@harlet following your example results in
that.initGoogleApi is not a function
Because that is a component method. :)
Inside the event function, you can use this.$google
as you would normally do.
Ok thank you for the clarification. I thought you were implying initGoogleApi was bound to the this context already. :)