簡體   English   中英

將數組提交到 Vuex 存儲突變

[英]Committing array to Vuex store mutation

存儲文件:

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 是一個 object 陣列。 當 Vuex 調用 setCases() 突變時,只有數組的第一個 object 會在 'items' 中傳遞。

這是為什么?

看這個: https://vuex.vuejs.org/guide/mutations.html [參見對象樣式提交部分]

使用對象樣式提交時,整個 object 將作為有效負載傳遞給突變處理程序,因此處理程序保持不變

resp值應該可以作為突變items.items中的 items.items 訪問。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM