[Vuejs]-Force computed variable to update (Firebase VueJS)

0👍

Either move the block

this.additionaluserinfo = this.$store.state.additionaluserinfo
if (this.$store.state.additionaluserinfo.role === 'admin' || this.$store.state.additionaluserinfo.role === 'superadmin') {
  this.isAdmin = true
}
if (this.$store.state.additionaluserinfo.role === 'superadmin') {
  this.isSuperAdmin = true
}

inside this.$store.dispatch('setAdditionalUserInfo', doc.data()).then(() => { /* */ }) or else that code would be evaluated before data are dispatched into the store (data fetching is async)

Or, better, just remove it and then add:

computed: {
    role: () => this.$store.state.additionaluserinfo ? this.$store.state.additionaluserinfo.role : '',
    isAdmin: () => this.role === 'admin' || this.role === 'superadmin', // remove isAdmin from data()
    isSuperAdmin: () => this.role === 'superadmin',
}

Leave a comment