In my vue.js store, I am able to access the state parameters within the computed section of a component:
computed: {
BASE_URL () {
return this.$store.state.BASE_URL;
}
However, when attempting to access the store in the methods of the same component:
methods: {
register: function () {
axios.post( this.BASE_URL + "/web/register", {
username: this.username,
password: this.password,
email: this.email
}).then(function(data){
this.$store.commit('saveToken', data.token);
console.log('token is set to:', this.$store.state.token)
});
}
},
An error is triggered in the console:
Uncaught (in promise) TypeError: Cannot read property '$store' of undefined
I have also tried $store
without including this
, yet encountered the same issue.
What could be causing this problem? How can it be resolved?