I need to set the currentId in the store. I have it in the component, everything fine in the console:
async created() {
const activityId = await this.$store.state.route.params.activityId
activityId: 'activityId'
console.log("here activityId: ", activityId)
console.log('print all params: ', this.$store.state.route.params)
console.log("STORE: ", this.$store.state)
},
I've organised the store in modules, the one I'm working on is activity.js and it's working fine (I have all the activities saved in the store). I now need to set the current id and then set the single activity according to it (so I can access its data). Removing the non inherent code, what I have is:
import {
activityId
} from '@/views/ActivityDetail'
const state = {
currentActivityId: activityId
}
const mutations = {
SET_CURRENT_ACTIVITY_ID: (state, currentActivityId) => {
state.currentActivityId = currentActivityId
}
}
const actions = {
setCurrentActivityId({
commit
}) {
return new Promise(resolve => {
commit('SET_CURRENT_ACTIVITY_ID', '')
resolve()
})
}
}
export default {
namespaced: true,
state,
mutations,
actions
}
In the module 'getters' I have, among the others (that are working fine):
activityId: state => state.activity.activityId,
Still activityId: undefined
I have sync (store, router)
working, also mode: 'history'
in the router, because before this I tried:
import {router} from '@/router'
const state = {
currentActivityId: router.currentRoute.params.activityId,
}
I didn't do any change regarding the mode: history, so I don't know if the problem can be found here. But commenting it and making use of the currentRoute did not solve the problem.
The versions installed in my app are: "vue-router": "3.0.6", "vuex": "^3.1.0", "vuex-router-sync": "^5.0.0"
Still activityId: undefined
Can anyone help, please?
Thank you
this.$store.commit('relative path to exact mutation method', your data)
– SMAKSSconst activityId = ...
seems strange to have a const instead of alet
here .. – DavidPistate.currentActivityId
. So,activityId: state => state.currentActivityId
? – Wes Doyle