我在Vue组件中有一个使用firebase登录用户的登录方法.我使用的计算性能user,message以及hasErrors.当这个方法运行时,它进入catch函数,但是这个错误出现了:
Uncaught TypeError: Cannot set property 'message' of undefined.我已经尝试直接更改vuex状态(因为这是计算的prop所做的),但这会产生相同的错误.这是我正在使用的方法:
login: function (event) {
// ... more stuff
// Sign-in the user with the email and password
firebase.auth().signInWithEmailAndPassword(this.email, this.password)
.then(function (data) {
this.user = firebase.auth().currentUser
}).catch(function (error) {
this.message = error.message
this.hasErrors = true
})
// ...
}
Run Code Online (Sandbox Code Playgroud)
这是计算的道具的样子:
message: {
get () {
return this.auth.message // mapState(['auth'])
},
set (value) {
this.$store.commit('authMessage', value)
}
}
Run Code Online (Sandbox Code Playgroud)
我很确定这个问题与它内部的问题有关Promise.那么如何在firebase中访问计算属性Promise呢?