vue.draggable.next: Clone - allow duplicates and how to key by index?

https://github.com/SortableJS/vue.draggable.next/blob/master/example/components/clone.vue

How could I pass the index in the itemKey prop instead of a value from the object. In my case in want to allow duplicates inside the array that the items are being dropped to.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 3
  • Comments: 16

Most upvoted comments

it doesn’t seem possible the default should be set to index automatically tbh…

i’ve run into same issue… am a bit puzzled by the most simple case of plain array with no props not being covered 😦

I did it this way:

<draggable
    v-model="myArray"
    :item-key="((item) => myArray.indexOf(item))"
    ...
    >
 
   <!-- ... -->
</draggable>

Not beautiful but works fine.

EDIT: Will only work if your array elements are unique. (Two objects with the same content are also unique when they are two different instances.)