vue-authenticate: $auth 变量在哪里定义的?
vue-authenticate: Where is the $auth variable defined?
我正在尝试实施 vue-authenticate,但我对从他们的文档中获取的以下示例代码有疑问:
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
属性从哪里来的?我看不到它在任何地方定义。我查看了文档和存储库中的示例代码,但都没有提供任何帮助。
如您所知,vue-authenticate 是 Vue-plugin。
并且当你使用这个插件的时候使用就行了。
Vue.use(VueAuthenticate, ...data)
这是它在 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
}
}
})
您可能还想在 Adding Instance Properties 上阅读此文档。
我正在尝试实施 vue-authenticate,但我对从他们的文档中获取的以下示例代码有疑问:
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
属性从哪里来的?我看不到它在任何地方定义。我查看了文档和存储库中的示例代码,但都没有提供任何帮助。
如您所知,vue-authenticate 是 Vue-plugin。
并且当你使用这个插件的时候使用就行了。
Vue.use(VueAuthenticate, ...data)
这是它在 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
}
}
})
您可能还想在 Adding Instance Properties 上阅读此文档。