1
votes

I cloned this simple admin dashboard made with VueJs + AdminLTE project into my local, so far everything works ... but I am currently struggling to find out how to get the stored state from vuex specially from this line of code which I modified to:

// if user loggedin
if(response.data && response.status == 200){
  this.$store.commit("USERNAME", data.username)
  this.$store.commit("TEL", data.tel)
  this.$store.commit('EMAIL', data.email)

  this.$router.push({ path: '/' })
}

Once the page is redirected I am trying to get the username, tel, email but It doesn't exist.

I did console.log(this.$store) I see many contents but not the user info

1

1 Answers

2
votes
this.$store.commit("USERNAME", data.username)

Above code will not set the username to the store. You need to call corresponding mutation in your commit . For example

this.$store.commit("SET_USER", data);

It will set the corresponding user data to the 'user' state in the store. Now you can get the corresponding user info using

   `this.$store.state.user`

The above call will contains all the user info like email, tel, username etc