During runtime, the object payload I pass as a secondary parameter to my Vuex mutation method is always undefined. Both my Vuex and component files are written in TypeScript.
My index.ts file for my Vuex store looks like this (note that I'm using the modular store approach):
import Profile from '@/models/Profile'
import { createStore } from 'vuex'
const userModule = {
state: () => ({
profile: Profile
}),
mutations: {
setProfile (state:any, profile: Profile) {
// `state` is the local module state
state.profile = profile //**RUNTIME ERROR: profile = undefined
}
},
getters: {
getProfile (state:any) {
return state.profile
}
}
}
export default createStore({
state: {
},
mutations: {
},
actions: {
},
modules: {
user: userModule
}
})
I commit to the store from my Vue component's methods like this:
<script lang="ts">
export default Vue.extend({
methods: {
fetchProfile() {
axios
.get("/getUser", requestHeader)
.then((profileResponse: Profile) => {
//store profile in Vue Store
store.commit('setProfile', profileResponse)
})
}
}
})
</script>
What am I doing wrong?