In my Vuex module, I have a simple setup for managing a global date object:
import moment from 'moment';
const state = {
date: moment()
}
// getters
const getters = {
date: state => state.date,
daysInMonth: state => state.date.daysInMonth()
}
// mutations
const mutations = {
subtractOneDay(state) {
state.date.subtract(1, 'days');
}
}
export default {
state,
getters,
mutations
}
I'm having an issue with one of my child components:
import { mapGetters, mapMutations } from 'vuex';
export default {
computed: Object.assign(mapGetters(['date', 'daysInMonth']), {}),
methods: {
subtractOneDay() {
this.$store.commit('subtractOneDay');
console.log(this.date.format('YYYY-MM-DD'), this.date.daysInMonth(), this.daysInMonth)
}
},
created() {
console.log('blocks created')
},
mounted() {
console.log('blocks mounted')
}
}
I am struggling to update the computed property daysInMonth
when the date
is changed.