[Vuejs]-Saving data to store VUEX

0👍

If you already know how to use Vuex to store data in a todo app, there is nothing different about storing user data. Vuex just works with data, period. So you can either commit a mutation or dispatch an action and pass along your data.

0👍

Actually you must store user data into the store, and also store data into browser’s localStorage to persist user data on refresh. Big frameworks like NuxtJs are working this way.

 .then(() => {
        console.log('user auth = ' + this.user.uid)

        this.$store.dispatch('storeJustLoggedInUser', this.user.uid);
 })

In your vuex store:

actions: {
    storeJustLoggedInUser({commit, state}, uid){
          commit('STORE_USER_UID', uid)
   }
}

This is just a pseudo code, hopefully you get the idea!

Leave a comment