Moved the script src for Google Maps API from head of index.html to component, using load script plugin

This commit is contained in:
Leah Schumann 2022-01-10 10:05:46 -05:00
parent 9ead873449
commit 3b7a650eb9
6 changed files with 13989 additions and 4716 deletions

15
2.0.0 Normal file
View file

@ -0,0 +1,15 @@
removed 2 packages, and audited 1692 packages in 8s
94 packages are looking for funding
run `npm fund` for details
103 vulnerabilities (88 moderate, 15 high)
To address issues that do not require attention, run:
npm audit fix
To address all issues (including breaking changes), run:
npm audit fix --force
Run `npm audit` for details.

18537
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -19,7 +19,7 @@
"vue": "^3.0.0",
"vue-google-autocomplete": "^1.1.2",
"vue-place-autocomplete": "^0.5.3",
"vue-plugin-load-script": "^1.3.5",
"vue-plugin-load-script": "^2.1.0",
"vue-router": "^4.0.11",
"vuex": "^4.0.2",
"vuex-persistedstate": "^4.1.0"

View file

@ -9,7 +9,6 @@
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,300;0,400;0,500;1,300;1,400;1,500&display=swap" rel="stylesheet">
<title><%= htmlWebpackPlugin.options.title %></title>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDptGCkOPgN2uWJOy4ou4M33phRD4MAoJo&libraries=places"></script>
</head>
<body>
<noscript>

View file

@ -31,9 +31,15 @@ export default {
//FormField
//VueGoogleAutocomplete
},
mounted() {
this.autocomplete = new window.google.maps.places.Autocomplete(
(this.$refs.autocomplete),
let self = this;
this.$loadScript("https://maps.googleapis.com/maps/api/js?key=AIzaSyDptGCkOPgN2uWJOy4ou4M33phRD4MAoJo&libraries=places")
.then(() => {
// Script is loaded, do something
self.autocomplete = new window.google.maps.places.Autocomplete(
(self.$refs.autocomplete),
{
componentRestrictions: { country: ["us"] },
fields: ["address_components"],
@ -41,8 +47,8 @@ export default {
}
);
this.autocomplete.addListener('place_changed', () => {
let place = this.autocomplete.getPlace();
self.autocomplete.addListener('place_changed', () => {
let place = self.autocomplete.getPlace();
let address1 = "";
let postcode = "";
@ -84,6 +90,11 @@ export default {
addressField1.value = address1 + ' ' + postcode;
}
});
})
.catch(() => {
// Failed to fetch script
console.log("Unable to load Google Places API script")
});
},
};

View file

@ -1,4 +1,5 @@
import { createApp } from "vue";
import LoadScript from "vue-plugin-load-script";
import App from "./App.vue";
import router from "./router";
import store from "@/store";
@ -10,7 +11,7 @@ const vueApp = createApp(App);
vueApp.use(router);
vueApp.use(store);
vueApp.use(LoadScript);
vueApp.mixin(baseMixin);
vueApp.mount("#app");