140
rated 0 times
[
141]
[
1]
/ answers: 1 / hits: 5728
/ 5 Years ago, sun, december 1, 2019, 12:00:00
I am trying to get a data from my firebase collection. When I console. the doc.data().name it is returning the name but when I am trying to assign the doc.data().name to a variable it is showing me an error of undefined. I am using Vuex and firebase.
created() {
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
console.log(user.uid);
firebase.firestore().collection(profiles).doc(user.uid)
.get()
.then(function(doc) {
console.log(Document data:, doc.data().name); // Getting value from firebase
this.profile.name = doc.data().name; // Getting Undefined Here
})
.catch(function(error) {
console.log(Error getting document:, error);
});
} else {
}
});
}
data() {
return {
profile: {
name: null
}
};
},
More From » firebase