我有Vuex
全局日期对象的简单模块:
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
}
我的子组件之一:
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')
}
}
基本上我需要在更改时获得一个月中的几天(29、29、30 或 31)date
。
问题是计算属性daysInMonth
不会改变......