Utilizing Vuex in my app is integral for executing asynchronous tasks, such as logging a user into the application. Upon successful login and execution of axios.then(), I aim to notify the component from which I invoked this.$store.dispatch('login', {username: userObj.username, password: userObj.password});
data() {
test: false
},
methods: {
login() {
const userObj = {
username: this.username,
password: this.password
};
console.log(userObj);
this.$store.dispatch('login',
{
username: userObj.username, password: userObj.password
});
}
},
Vuex:
const actions = {
login({ commit }, authData) {
axios.post('/login', {
username: authData.username,
password: authData.password
})
.then(resp => {
console.log(resp);
localStorage.setItem('token', resp.data.authToken);
localStorage.setItem('userId', resp.data.id);
localStorage.setItem('user', resp.data);
commit('storeUser', resp.data);
router.replace('/dashboard');
})
.catch(e => {
console.log(e);
alert('Something went wrong, try again')
});
},
}
In the .then() method within Vuex, I am looking for assistance in altering the test property to true in my component. Any advice or solutions would be greatly appreciated!