While replicating:
https://sortablejs.github.io/Vue.Draggable/#/nested-example
(code)
I ran into an issue related to the model; how can I add draggable to vue components instead of a raw json (as used in the example).
What I want to do is, add drag and drop to:
https://codesandbox.io/s/gg1en
(each item can be moved ("dragged") from one group to another, each group can be dragged from a lower position to an upper one (and vice-versa).
I tried:
https://codesandbox.io/s/quirky-sutherland-5s2zz?file=/src/components/InventorySectionC.vue
and got:
Unexpected mutation of "itemSectionData" prop. (vue/no-mutating-props)
but in this case the data comes from (through?) a prop.
The hierarchy of components is:
ChromePage
--> InventorySectionC
--> InventorySectionGroupC
--> InventorySectionGroupItemC
I need components instead of plain JSON as each component has additional features (e.g. CRUD).
How should I go about combining components with draggable?
If you have a component prop that's being mutated, there are multiple options:
value
and sent $emit('input', this.value)
to update it.prop.sync
modifier, which is kinda the same as using v-model
but the prop has a specific name. Use :data.sync="myItems"
on the parent, and run $emit('update:data', this.data)
inside the component to update it.<template>
<draggable v-model="_data"></draggable>
</template>
<script>
props: {
data: { type: Object, required: true }
}
data() {
return {
_data: {}
}
}
mounted() {
// Copy
Object.assign(this._data, this.data)
}
</script>