2017-08-11 50 views
1

嘿家伙我使用这lib,此刻我正在尝试一个简单的排序,想象我有一个数组与3个元素,我想改变他的立场与拖动,我是能够做到这一点。事情是,当我swich的地方我的JSON数组不更新。VueJS可拖拽/可排序JSON不更新

我这样做:

我的列表:

<draggable v-model="getDocumentAttributes"> 
     <div v-if="value.key != 'Document'" class="panel panel-primary" v-for="(value, key, index) in 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吸气:

getDocumentAttributes(){ 
    return this.$store.getters.getDocumentAttributes; 
} 

Finaly我的名单,我的getter函数在vuex方面:

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

[...]

getDocumentAttributes: (state) => { 
     return state.document.atributes; 
    }, 

回答

2

使用本地数据在VUE部件,这将通过VUE-拖动进行修改。

它又是一样的,你只能用突变来改变vuex状态。不适用于getter,不适用于计算属性,不适用于操作。计算属性是只读的默认情况下,这里的插件的自述,你可以看到如何使用它们https://github.com/SortableJS/Vue.Draggable#with-vuex

+0

我对vuex有同样的解决方案,但是我的setter永远不会被调用,我需要为此做些什么? –

+0

。^。 “......你只能用突变来改变vuex状态。” – Reiner

+0

我知道,但它不解释随着dragable /可排序如何做到这一点,我应该在哪里打电话集() –

0
getDocumentAttributes: { 
    get() { 
     return this.$store.getters.getDocumentAttributes; 
    } 
    set (value) { 
     this.$store.commit('YOUR.COMMIT.TYPE', value) 
    } 
} 

赖纳指出,计算出的属性是只读的默认。 这是如何改变这一点。