我正在尝试使用 NuxtJSdayjs
模块将初始月份设置为当前月份。
为什么我可以this.$dayjs
在动作中使用但不能在状态中使用?它不应该是全球可访问的吗?
我怎样才能在状态中初始化当前月份?
export const state = () => ({
month: this.$dayjs().startOf('month'), //THIS LINE DOESNT WORK
})
export const mutations = { }
export const actions = {
bindOngepland: firestoreAction(function ({ bindFirestoreRef, rootState }) {
const month = this.$dayjs().startOf('month') // THIS LINE DOES WORK
const nextMonth = state.month.add(1, 'month')
}),
setNextMonth({ }) {
},
}
在这个简化的示例中,我收到undefined
第 2 行的错误。this
似乎是undefined
.