[Vuejs]-Vuex | Map state โ€“ Scoping issue in beforeMount() on page refresh

0๐Ÿ‘

I think what might be happening is that your userProfile data in Vuex is set only after the component has mounted when you directly refresh the page? In that case userProfile.name might still be undefined when you assign it. If this is what happens, you could add a watcher in this component that checks for changes in the userProfile and updates the localProfile if it hasnโ€™t been set during the mount.

Also: have you looked at the v-once directive? https://v2.vuejs.org/v2/api/#v-once
This should prevent the username from being updated when the value changes without having to reference a local copy.

Leave a comment