您是否恰好知道如何将用户设置为currentUser? 我正在使用vuefire和firebase。 user.uid 返回undefined。
auc_precision_recall
这是我的其余代码:
<td v-if="(building['key'] && building['key'].child('ownerId')) == user.uid">
<p >{{building['.key']}} + {{user.uid}}</p>
</td>
我试图通过beforeCreate hook中的商店来实现:
import firebase,{ db, usersRef, buildingsRef } from '../firebase-config';
import { store } from '../store/store';
export default {
firebase() {
// from my understanding this just gives me a quick access to the Refs and a short nomenclature
return {
users: usersRef,
buildings: buildingsRef,
}
},
name: 'buildings',
data () {
return {
user: "",
building: {
name: '',
address: '',
comments: '',
ownerId: '',
},
}
},
如果我在create hook中设置用户,就像这样:
beforeCreate () {
this.$store.dispatch('setUser');
let user = this.$store.getters.getUser;
console.log(user); // this works!!!
this.$set(this.user, 'uid', user.uid )
}
},
我收到此错误:
答案 0 :(得分:2)
在Vue中,状态(又名data
属性)是initialized between the beforeCreate
and created
个钩子。
因此,您对data
beforeCreate
所做的任何更改丢失。
将您的挂钩更改为created
created() { // changed this line
this.$store.dispatch('setUser');
let user = this.$store.getters.getUser;
console.log(user); // this works!!!
this.$set(this.user, 'uid', user.uid)
}