how to implement Google Login API in VueJS? how to implement Google Login API in VueJS? vue.js vue.js

how to implement Google Login API in VueJS?


data-onsuccess="onSignIn" is looking for a global onSignIn function. You need to put onSignIn outside of Vue component.

Another way is using gapi.signin2.render to render sign-in button, then you can use onSignIn inside Vue component:

<template>  <div id="google-signin-button"></div></template><script>export default {  mounted() {    gapi.signin2.render('google-signin-button', {      onsuccess: this.onSignIn    })  },  methods: {    onSignIn (user) {      const profile = user.getBasicProfile()    }  }}</script>

For more reference: https://developers.google.com/identity/sign-in/web/build-button


In case somebody needs a plugin to start working right away without too much setup, try this vue-google-signin-button-directive.