Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js vue身份验证:在哪里定义了$auth变量?_Vue.js_Vue Authenticate - Fatal编程技术网

Vue.js vue身份验证:在哪里定义了$auth变量?

Vue.js vue身份验证:在哪里定义了$auth变量?,vue.js,vue-authenticate,Vue.js,Vue Authenticate,我正在尝试实现,但以下示例代码取自他们的文档,我遇到了一个问题: new Vue({ methods: { login: function () { this.$auth.login({ email, password }).then(function () { // Execute application logic after successful login }) }, register: function () {

我正在尝试实现,但以下示例代码取自他们的文档,我遇到了一个问题:

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中的示例代码,但都没有提供任何帮助。

正如您所知,vue authenticate是一个vue插件

当你使用这个插件的时候,使用这个行

Vue.use(VueAuthenticate, ...data)
这就是它的定义


此外,您可能还需要在上浏览此文档。

它已经提供。它应该在调用Vue.useVueAuthenticate、options之后定义。如果您希望解决特定错误,请提供有关您所遇到错误的更多详细信息。@Thebluefish I'm get$auth未定义。我使用了Vue.use,并在文档后面添加了authenticate方法。我现在90分钟内无法发布新问题,因此我将再次尝试Google/docs。您是否尝试引用此。传递给的回调函数中的$auth?或者您是否在任何地方使用arrow函数=>呢?因为您可能引用了不正确的。你猜到了,问题是我在顶层方法函数中使用了箭头函数。非常感谢。
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
    }
  }
})