I send email and password to Vuex:
this.$store.dispatch('login', {
email: this.email,
password: this.password
}).then(console.log(this.$store.state.login));
In Vuex I use Axios, this code is on actions
:
login(context, payload) {
return new Promise((resolve, reject) => {
let options = {
method: "post",
data: payload,
url: "/api/login"
};
axios(options)
.then(response => {
context.commit("login", response.data);
resolve();
})
});
},
next I send data to the mutations
:
login(state, login){
state.login = login;
},
And to the state
:
login: null
This is form:
<form method="post" @submit.prevent="sendLogin">
<input type="email" id="email" name="email" v-model="email">
<input type="password" id="password" name="password" v-model="password">
<button type="submit" class="btn btn-primary">Submit</button>
</form>
When I write email
and password
and click FIRST time Submit
.then(console.log(this.$store.state.login));
return NULL
, but when I second click Submit
log
return correctly data.
How I can resolve this ?