gpt4 book ai didi

javascript - Firebase Cloud Firestore 报错 + Vue + Vuex (firebase.firestore.QuerySnapshot)

转载 作者:搜寻专家 更新时间:2023-10-30 22:42:26 25 4
gpt4 key购买 nike

我发现 docChanges 看起来有些问题,它是一个函数,但是当我编写 docChanges().doc.data().userId 时出现此错误 store.js?3bf3: 21 未捕获的类型错误:无法读取未定义的属性“文档”

::更新

我想登录/注册,但我现在收到这个错误一切正常,但登录功能中的 this.$router.push('/dashboard') 不行。为什么?

商店.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 = []
}
}
}

登录错误码

Error code of Login登录.vue组件

             <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
})
},
}

最佳答案

您调用 querySnapshot.docChanges 就好像它是一个数组:

querySnapshot.docChanges.length...
querySnapshot.docChanges[0]...

但是querySnapshot.docChanges是一个函数,所以你需要先调用函数,然后再得到一个数组:

querySnapshot.docChanges().length...
querySnapshot.docChanges()[0]...

关于javascript - Firebase Cloud Firestore 报错 + Vue + Vuex (firebase.firestore.QuerySnapshot),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51464180/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com