Vue.js 将数组提交到Vuex存储区
存储文件:Vue.js 将数组提交到Vuex存储区,vue.js,vuex,Vue.js,Vuex,存储文件: state: { ... cases: [], ... mutations: { setCases(state, items) { // items contains only the first object in the array ... 组成部分: // resp is an array received from axios.get: this.$store.commit({ type: 'setCa
state: {
...
cases: [],
...
mutations: {
setCases(state, items) {
// items contains only the first object in the array
...
组成部分:
// resp is an array received from axios.get:
this.$store.commit({
type: 'setCases',
items: resp
})
resp是一个对象数组。Vuex调用setCases()时,只有数组的第一个对象在“items”中传递
为什么会这样?看看这个:[参见对象样式提交部分]
使用对象样式提交时,整个对象将作为
将有效负载分配给变异处理程序,因此处理程序保持不变
resp
值应该可以作为items.items
在变异函数中访问。看看这个:[参见对象样式提交部分]```当使用对象样式提交时,整个对象将作为有效负载传递给变异处理程序,因此,处理程序保持不变,``应该可以访问resp
值作为items。在变异函数中,items
,对吗?你能证实这是真的吗?太好了@gvk,非常感谢,你救了我一天!酷。如果其他人在没有完全RTFM的情况下偶然发现此问题,则添加此答案:-)