我正在尝试实现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属性从何而来?我在任何地方都看不到它的定义。我已经查看了repo中的文档和示例代码,但都没有提供任何帮助。
发布于 2018-03-01 03:50:26
如您所知,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上通读此文档。
https://stackoverflow.com/questions/49037349
复制相似问题