When I call a store action from the main layout (default.vue in Nuxt.js), and then call a state mutation within the mutations export, I encounter an error. Can anyone help me figure out why?
The error message in console: http://prntscr.com/rwvfjf
Here is the relevant code:
Code snippet from default.vue:
created () {
this.$store.dispatch("update_user");
...
}
Code snippet from store/index.js:
export const state = {
...
state: null,
}
export const actions {
...
update_user({commit}) {commit("update_user")}
}
export const mutations = {
async update_user(state) {
if (state.token == undefined) {
return
}
if (this.$axios.defaults.headers.common["authorization"] == undefined) {
this.$axios.defaults.headers.common["authorization"] = state.token
}
var user = await this.$axios.get("/api/v1/user/@me");
state.user = user;
},
}