I am displaying the name of the current user after querying it from the firestore database like so:
JavaScript
x
9
1
database
2
.collection("members")
3
.doc(id)
4
.get()
5
.then(doc => {
6
this.currentUserDetails.name =
7
doc.data().first_name + " " + doc.data().last_name;
8
});
9
then after fetching the result it should be something like below:
However it does not display the name after the result is fetched immediately,since it takes some time. I am only able to show it after I change some property such as the margin.
How can I display it immediately the result is caught.
My template code:
JavaScript
1
8
1
<v-navigation-drawer app v-model="drawer" class="text-xs-center">
2
<v-avatar class="mt-5 mb-4" size="100">
3
<img src="/img/avatars/admin.png">
4
</v-avatar>
5
6
<p class="subheading font-weight-bold mb-1">{{currentUserDetails.name}}</p>
7
<p class="text-capitalize mb-3">{{currentUserDetails.userType}}</p>
8
Advertisement
Answer
Assign new object reference in the this.currentUserDetails
for reactivity.
JavaScript
1
6
1
this.currentUserDetails.name =
2
doc.data().first_name + " " + doc.data().last_name;
3
4
// assign new object reference in 'this.currentUserDetails'
5
this.currentUserDetails = Object.assign({}, this.currentUserDetails)
6
Alternate: you can use this.$set()
to get the reactivity working:
JavaScript
1
3
1
// using this.$set(...)
2
this.$set(this.currentUserDetails, 'name', doc.data().first_name + " " + doc.data().last_name);
3