2017-08-08 91 views
0

我使用可拖動和可排序與vuejs,我有一個問題,每次我改變兩個div的位置,例如,他們改變,但json數組不更新。排序陣列沒有更新時更改位置

我與vuex的工作,我有我的組件模板這個網站:

<draggable v-model="myList"> 
    <div class="panel panel-primary" v-for="(value, key, index) in this.$store.getters.getDocumentAttributes"> 
     <div class="panel-body quote"> 
      <span @click="removeSection(index,key)" class="pull-right glyphicon glyphicon-remove text-info"></span> 
      <p>{{value.key}}</p> 
     </div> 
    </div> 
</draggable> 

然後我得到了我的計算道具是獲取和設置是來自vuex數據,

computed: { 
    sections() { 
     return this.$store.getters.getDocument; 
    }, 
    myList: { 
     get() { 
      return this.$store.getters.getDocument.getDocumentAttributes; 
     }, 
     set(value) { 
      this.$store.commit('updateList', value) 
     } 
    } 

}, 

的updateList應該更新我的列表(如果我想好),所以我有這樣的:

}, 
mutations: { 
     updateList: (state,list) => { 
     state.Doc.atributes = list; 
    } 
}, 



document: { "id": "0", "atributes": [] }, 

我嘗試重新將舊數組與新的匹配與atributes數組,任何幫助?

ps:文件在數據裏面,我只是試着放置必要的代碼。

感謝

+0

你可以有你有什麼迄今所以我們可以看到發生了什麼一點點演示? –

+0

對不起atm我不能這樣做真的想,但我試圖解釋更好 –

+0

此刻我可以拖動一個div和兩個div之間的變化位置,但他們不會更新我的json,我的json不' t refresh:/, –

回答

1

我有一個類似的設置,並得到這個在計算財產使用this.$forceUpdate()工作。

computed: { 
    sections() { 
    return this.$store.getters.getDocument; 
    }, 
    myList: { 
    get() { 
     return this.$store.getters.getDocument.getDocumentAttributes; 
    }, 
    set (value) { 
     this.$forceUpdate() 
     this.$store.commit('updateList', value) 
    } 
    } 
}, 

編輯:

我假設你也想直接派遣一個突變,因爲你沒有列出的任何行動,這是不正確。

你應該分派行動,即犯了突變 ...請看下圖:

actions: { 
    updateList: ({ commit }, list) { 
    commit('updateList', list) 
    } 
}, 
mutations: { 
    updateList: (state, list) => { 
    state.Doc.atributes = list; 
    } 
}, 
+0

你有什麼關於vuex中的updateList側? –

+0

我相當於你有什麼。 –

+0

好的,但我的updateList永遠不會被調用,這是我的問題:D –