[Vuejs]-Load gapi.auth2 when VueJs starts

0👍

I assume that gapi.auth2.getAuthInstance().currentUser.get() is an async task for that you can use the async created hook which is triggered on the creation of your instance and there assign the value to your data :

// import gapi from '....'
var app = new Vue({
  el: '#app',
  async created() {
    try {
      let res = await gapi.auth2.getAuthInstance().currentUser.get();
      this.user = res.data
    } catch (e) {
      console.log(e)
    }
  },
  data: {
    user: null,
  }
})

and make sure you have imported gapi at the top of your script.

Leave a comment