更新:此错误仅在启用vuex严格模式时发生。
我正在构建一个具有firebase身份验证的Vue应用程序,但是该应用程序在以下错误消息中失败:
Vue warn:在对观察者的回调中出错“函数() {返回this._data.$$state }":”错误: vuex不变异vuex存储状态之外的变异处理程序。“ 错误: vuex不变异vuex存储状态之外的变异处理程序。 未指定的RangeError:超过最大调用堆栈大小
当我将用户提交到我的main.ts文件中的Vuex存储时,会发生错误:
firebase.auth().onAuthStateChanged(user => {
if (user) {
store.commit(constants.auth.SET_USER, user) // THIS LINE
store.commit(constants.auth.SET_AUTHENTICATED, true)
router.push('/')
} else {
store.commit(constants.auth.SET_USER, null)
store.commit(constants.auth.SET_AUTHENTICATED, false)
router.push('/signup')
}
if (!app) {
app = new Vue({
router,
store,
render: (h) => h(App),
}).$mount('#app')
}
})
这是我的变异:
[constants.auth.SET_USER](state: AuthState, payload: firebase.User): void {
state.user = payload
}
我可以从Vue devtools中看出,实际发生了突变,并且用户已经提交给商店,但我不知道为什么会发生此错误。你能帮帮我吗?
我已经尝试过注释应用程序中的几乎所有其他内容,而这是唯一会引起任何麻烦的部分。
发布于 2019-08-06 15:37:05
将user.toJSON()
存储在您所在的州。firebase用户是一个复杂的对象,不应该存储在vuex状态。
发布于 2019-08-26 21:25:39
我认为您可能需要将firebase.auth().onAuthStateChanged
封装在new Promise
中。
看看这个例子:https://forum.vuejs.org/t/vue-routes-firebase-auth-sync-problem/4470#post2
https://stackoverflow.com/questions/55228739
复制相似问题