【发布时间】:2018-12-30 01:02:06
【问题描述】:
我发现 docChanges 看起来有些问题,它是一个函数,但是当我写 docChanges().doc.data().userId 时出现此错误 store.js?3bf3:21 Uncaught TypeError: Cannot read property 'doc' of undefined
::更新
我想登录/注册,但我现在收到此错误
一切正常,但登录功能中的this.$router.push('/dashboard') 没有。为什么?
Store.js
state: {
currentUser: null,
userProfile: {},
posts: [],
hiddenPosts: []
},
actions: {
clearData({ commit }) {
commit('setCurrentUser', null)
commit('setUserProfile', {})
commit('setPosts', null)
},
fetchUserProfile({ commit, state }) {
fb.usersCollection.doc(state.currentUser.uid).get().then(res => {
commit('setUserProfile', res.data())
}).catch(err => {
console.log(err)
})
}
},
mutations: {
setCurrentUser(state, val) {
state.currentUser = val
},
setUserProfile(state, val) {
state.userProfile = val
},
setPosts(state, val) {
if (val) {
state.posts = val
} else {
state.posts = []
}
},
setHiddenPosts(state, val) {
if (val) {
if (!state.hiddenPosts.some(x => x.id === val.id)) {
state.hiddenPosts.unshift(val)
}
} else {
state.hiddenPosts = []
}
}
}
登录错误码
<form v-if="showLoginForm" @submit.prevent>
<h1>Welcome Back</h1>
<label for="email1">Email</label>
<input v-model.trim="loginForm.email" type="text"
placeholder="you@email.com" id="email1" />
<label for="password1">Password</label>
<input v-model.trim="loginForm.password" type="password"
placeholder="******" id="password1" />
<button @click="login" class="button">Log In</button>
</form>
data() {
return {
loginForm: {
email: '',
password: ''
}
}
},
methods: {
login() {
this.performingRequest = true
fb.auth.signInWithEmailAndPassword(this.loginForm.email,
this.loginForm.password).then(user => {
this.$store.commit('setCurrentUser', user)
this.$store.dispatch('fetchUserProfile')
this.performingRequest = false
this.$router.push('/dashboard')
}).catch(err => {
console.log(err)
this.performingRequest = false
this.errorMsg = err.message
})
},
}
【问题讨论】:
标签: javascript firebase vue.js google-cloud-firestore