Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Following the short example runs code before script is loaded. #13

Open
robbylucia opened this issue Jan 18, 2020 · 4 comments
Open

Following the short example runs code before script is loaded. #13

robbylucia opened this issue Jan 18, 2020 · 4 comments

Comments

@robbylucia
Copy link

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?

@harlet
Copy link

harlet commented Mar 31, 2020

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();
    });
  },

@pbjer
Copy link

pbjer commented Apr 23, 2020

@harlet following your example results in
that.initGoogleApi is not a function

@harlet
Copy link

harlet commented Apr 23, 2020

Because that is a component method. :)
Inside the event function, you can use this.$google as you would normally do.

@pbjer
Copy link

pbjer commented Apr 23, 2020

Ok thank you for the clarification. I thought you were implying initGoogleApi was bound to the this context already. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants