Whenever I include the line
this.$store.commit('disconnect');
, it throws a "this is undefined" error. Any suggestions on how to resolve this issue?
store/index.js :
export const state = () => ({
log: false,
user: {token: null, id: null, username: null, email: null, created_at: null, pseudo: null}
})
export const mutations = {
connect (state) {
state.log = true
},
disconnect (state) {
state.log = false,
state.user.id = null,
state.user.username = null,
state.user.email = null,
state.user.created_at = null,
state.user.pseudo = null
}
}
index.vue
<script>
import axios from "axios";
methods: {
async login() {
var self = this;
const auth_res = axios({
method:'post',
url:'http://127.0.0.1:8000/v2.0/auth',
data:{
username: this.username,
password: this.password
}
}).then(function(res){
this.$store.commit('disconnect');
self.$router.push('/');
}).catch(function (erreur) {
console.log(erreur);
});
}
}
}
</script>
Everything works fine if I remove the commit
line from the index.vue
file. However, I need to use it for my functionality. Is there a way to fix this problem?
Thank you in advance.