我有现成的常量需要保存在状态中: const day = "25/02/2020"; const timeStart = "08:00"; const timeEnd = "00:00";在我的 vuex 文件中我有这个: export default new Vuex.Store ({ state: { dateSelected: [], // selected date }, mutations: { saveDateSelected (state, [newDateSelected, newTimeStart, newTimeEnd]) { const newobject = { DateStart: newDateSelected + "-" + newTimeStart, DateEnd: newDateSelected + "-" + newTimeEnd, }; state.dateSelected.push (newobject); } },当我在我的组件中时,我会通过以下方式调用数据: this.saveDateSelected (day, timeStart, timeEnd);如果我执行“console.log (this.dateSelected);” 给我结果: DateEnd: "2 - /" DateStart: "2 - 5"什么时候应该给我: DateEnd: "25/02/2020 - 00:00" DateStart: "25/02/2020 - 08:00"
1 回答
皈依舞
TA贡献1851条经验 获得超3个赞
您不应该直接从组件调用存储突变方法。改为提交 this.$store.commit('saveDateSelected, [day, timeStart, timeEnd])
还要确保您通过computed
组件的属性正确访问组件中的 vuex 存储。
添加回答
举报
0/150
提交
取消