大家好,我正在使用这个lib,目前我正在尝试一个简单的可排序对象,想象一下我有一个包含3个元素的数组,我想通过拖动来更改他的位置,我现在可以这样做。关键是,当我将这些地方夹住时,我的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 getter的计算道具:

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


最后,在vuex端我的列表和我的getter函数:

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


[...]

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

最佳答案

使用vue组件中的本地数据,这将通过vue-draggable进行修改。

同样,您只能使用突变来更改vuex状态。不使用getter,不使用计算属性,也不使用操作。默认情况下,计算属性在插件的自述文件中为只读,您可以查看如何使用它们https://github.com/SortableJS/Vue.Draggable#with-vuex

10-05 20:43
查看更多