I am trying to add google authentication to my vue.js front end. This is a new project created through the CLI with typescript and component style syntax enabled (along with others) and also has a corresponding back end web server. I have been following this guide from google but I am very new to vue and gapi. I don't know how to load <script src="https://apis.google.com/js/platform.js" async defer></script>
into my app or how to use it once loaded. I've found examples like this on jsfiddle and a few other examples on stack overflow and other forums, but none seem to use typescript and component style syntax or are incomplete.
App.vue
<template>
<div id="app">
<div id="nav">
<router-link to="/">Login</router-link>
</div>
<router-view />
</div>
</template>
<style lang="scss">
</style>
Main.ts
import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
Vue.config.productionTip = false;
new Vue({
router,
store,
render: h => h(App)
}).$mount("#app");
Login.vue (View)
<template>
<div>
<Login />
</div>
</template>
<script>
// @ is an alias to /src
import Login from "@/components/Login.vue";
export default {
name: "login",
components: {
Login
}
};
</script>
Login.vue (Component)
<template>
<div>
<button>Sign in with Google</button>
</div>
</template>
<script lang="ts">
import { Component, Prop, Vue } from "vue-property-decorator";
@Component
export default class Login extends Vue {}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
</style>
script src="https://apis.google.com/js/platform.js" async defer></script>
or some other npm package which does the same is fine for you then I can create an example to show you how to use it. – Varit J Patel