-
Notifications
You must be signed in to change notification settings - Fork 53
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
Using vuetify-google-autocomplete with vue2-google-maps #60
Comments
I am just leaving a trail of my findings of the same problem. There are a number of issues:
My plugin code: import Vue from 'vue';
import * as VueGoogleMaps from 'vue2-google-maps';
const key = 'xxxxxxxx';
// @see https://www.npmjs.com/package/vue2-google-maps
Vue.use(VueGoogleMaps, {
load: {
key: key,
// This is required to use the Autocomplete plugin
libraries: 'places', // 'places,drawing,visualization'
},
});
// @see https://www.npmjs.com/package/vuetify-google-autocomplete
Vue.use(VuetifyGoogleAutocomplete, {
apiKey: key, // <-- removing apiKey means that the install code doesn't double load (which is another error)
}); So if you turn off the This in turn CAN be quietened by turning OFF geolocation. But that removes functionality and masks errors:
This is implemented:
But that means that the autocomplete now no longer works! Seems that immediate issues are to:
Tracking down the loading:
So the setup code is not being called because this listener is not triggered.
And that's because in the original init setup code, the callback from google calls code that sets
Setup from mounted:
|
To remove all the errors and not get double loading (and make no code changes). This is not a pleasure. Remove the plugin registration import Vue from 'vue';
import * as VueGoogleMaps from 'vue2-google-maps';
const key = 'xxxxxxxxs';
// @see https://www.npmjs.com/package/vue2-google-maps
Vue.use(VueGoogleMaps, {
load: {
key: key,
// This is required to use the Autocomplete plugin
libraries: 'places', // 'places,drawing,visualization'
},
});
// NO LONGER GLOBALLY REGISTERED
// @see https://www.npmjs.com/package/vuetify-google-autocomplete
/*
Vue.use(VuetifyGoogleAutocomplete, {
// apiKey: key,
// version: '...', // Optional
// language: '...', // Optional
});
*/ Then in the local component (from my documentation) /**
* A workaround 'timing' function that ensures google is loaded before the 'google-autocomplete' is loaded.
* This method is called when the gmap component is visible. Currently, this is a workaround to hold off loading
* the vuetify-google-autocomplete with a skeleton loader until ready
*
* Basic design:
*
* - skeleton loader around autocomplete
* - v-intersect on gmap triggers callback
* - callback that ensures google has loaded via map promise
*
* @example
*
* Template:
* <v-skeleton-loader :loading="loading">
* <vuetify-google-autocomplete ... />
* </v-skeleton-loader>
*
*
* <GmapMap
* ref="map"
* v-intersect.quiet="loaded"
* ... />
*
* Script: (ensure you import locally VuetifyGoogleAutocomplete and add to component)
*
* protected loading = true;
*
* private loaded(): void {
* this.$refs.map.$mapPromise.then(() => {
* this.loading = !Object.prototype.hasOwnProperty.call(window, 'google');
* });
* }
*
*
* Notes for typescript
*
* public $refs!: Refs<{ map: { $mapPromise: Promise<void> }; }>;
*
* interfaces.d.ts
*
* type Refs<T extends Record<string, unknown>> = Vue['$refs'] & T;
* declare module 'vuetify-google-autocomplete/lib/VuetifyGoogleAutocomplete';
*
* Ideally, this code check could have been in mounted, however, it doesn't work and many have tried.
* @see https://stackoverflow.com/questions/54355375/vue-js-refs-are-undefined-even-though-this-refs-shows-theyre
*
*/ |
@MadimetjaShika any chance of getting that pull request through at some stage? |
#109 Merged and published as v2.0.4. Please re-open if this is still an issue. |
The original error can still occur, sorry :-( (v2.0.4) There is a race condition if the field has focus too early. The 'autocomplete' field could be behind a promise. opened issue #112 |
I am having issues setting vuetify-google-autocomplete when I am also using vue2-google-maps, I only use the API key when I load google maps.
Apparently the API is not loading correctly on page refresh :/
The text was updated successfully, but these errors were encountered: