请帮助我。我已经工作了几天,试图解决此错误,并始终在相同的单击处理程序错误“用户未定义”下结束备份,但我不知道这意味着什么...这是vuejs / vuex / vuetify / firestore项目。请任何帮助将不胜感激。
来自store/index.js
updateUser({ commit, state },
payload) {
commit('setLoading', true);
commit('clearError');
firebase
.firestore()
.collection('users').doc(`users/${user.uid}`).add()
.then((data, payload) => {
const key = data.key;
let displayName = payload.name;
let address = payload.address;
let city = payload.city;
let state1 = payload.state1
let zip = payload.zip
let country = payload.country
let company = payload.company
let email = payload.email
let phoneNumber = payload.phone
commit('updateUser', {
id: key,
name: displayName,
phone: phoneNumber,
email: email,
address: address,
city: city,
state1: state1,
zip: zip,
country: country,
company: company
})
}).catch(err => {
console.log(err)
})
},
组件代码...
methods: {
onUpdate() {
this.$store.dispatch("updateUser", {
email: this.email,
name: this.name,
company: this.company,
address: this.address,
city: this.city,
state1: this.state1,
zip: this.zip,
country: this.zip,
phone: this.phone,
});
},
答案 0 :(得分:1)
假设user
是一个状态属性,即
state: {
loading: false,
errors: [],
user: null // here
},
那么您的Firestore docref应该是
.doc(`users/${state.user.uid}`)
由于您的操作执行异步操作,因此应考虑使其返回承诺,例如使其成为composable,例如
updateUser({ commit, state }, payload) {
commit('setLoading', true)
commit('clearError')
return firebase.firestore()... // note the "return" here