Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js 将数组提交到Vuex存储区_Vue.js_Vuex - Fatal编程技术网

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的情况下偶然发现此问题,则添加此答案:-)