【发布时间】:2020-05-23 08:34:38
【问题描述】:
我在 store/localStorage 中有一个数组来保存用户的 ID 和工作时间。但是 array.push 函数不起作用。
export const state = () => ({
Total: []
})
export const mutations = {
setTotal(state, value){
state.Total.push(value);
}
}
我在我的创建中有这个:
this.$store.commit("localStorage/setTotal", {id: this.signedInUserID, time: 0});
这是我得到的错误:
TypeError:state.Total.push 不是函数
【问题讨论】:
-
"localStorage/"前缀意味着你有一个命名空间的 Vuex 模块。你设置正确了吗? -
这段代码不足以说明问题所在
-
我有一个在 state 中调用 User 的对象和一个在 mutation 中的 setUser 函数,它工作正常。
-
我正在尝试向状态中的数组添加一个新对象,但出现错误:TypeError: state.Total.push is not a function 。如果你愿意,我会提供任何额外的代码,它会是什么?
标签: javascript vue.js state vuex store