首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >vue-authenticate:$auth变量在哪里定义?

vue-authenticate:$auth变量在哪里定义?
EN

Stack Overflow用户
提问于 2018-03-01 03:41:04
回答 1查看 1.1K关注 0票数 0

我正在尝试实现vue-authenticate,但是从他们的文档中摘取的以下示例代码出现了问题:

代码语言:javascript
复制
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
      })
    }
  }
})

$auth属性从何而来?我在任何地方都看不到它的定义。我已经查看了repo中的文档和示例代码,但都没有提供任何帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-01 03:50:26

如您所知,vue-authenticate是一个Vue-plugin。

当你使用这行代码来使用这个插件时。

代码语言:javascript
复制
Vue.use(VueAuthenticate, ...data)

这就是在this file中定义它的地方

代码语言:javascript
复制
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
    }
  }
})

此外,您可能想要在Adding Instance Properties上通读此文档。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49037349

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档