简体   繁体   中英

vue-authenticate: Where is the $auth variable defined?

I am trying to implement vue-authenticate , but I'm having an issue with the following example code taken from their documentation:

new Vue({
  methods: {
    login: function () {
      this.$auth.login({ email, password }).then(function () {
        // Execute application logic after successful login
      })
    },

    register: function () {
      this.$auth.register({ name, email, password }).then(function () {
        // Execute application logic after successful registration
      })
    }
  }
})

Where is the $auth property coming from? I can't see it defined anywhere. I've looked through the documentation, and the example code in the repo, but neither provide any help.

As you know vue-authenticate is a Vue-plugin.

And when you use this plugin using the line.

Vue.use(VueAuthenticate, ...data)

And this is where it gets defined in this file

Object.defineProperties(Vue.prototype, {
  $auth: {
    get() {
      if (!vueAuthInstance) {
        // Request handler library not found, throw error
        if (!this.$http) {
          throw new Error('Request handler instance not found')
        }

        vueAuthInstance = new VueAuthenticate(this.$http, options)
      }
      return vueAuthInstance
    }
  }
})

Also you may want to go through this documentation on Adding Instance Properties .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM