sortablejs-vue3
sortablejs-vue3 copied to clipboard
How set item-key when List type is string[]
Well, this is something I overlooked... at the moment, you can't. The easiest thing to do would be to adjust your data so each item has a unique key. If you want to make a pull request, the library could be modified to work with primitive arrays.
You can provide the item index to the item-key callback as you do with the item. This will allow us to use the index as the key as a solution.
+1 for this. In my case, my array contains the ids and the child components use this to access other data elsewhere. So I can use :itemKey="x => x"
I'm pretty sure this could be adapted for non-unique strings by changing line 162 of Sortable.vue to:
:key="getKey(item, index)"
and then using :itemKey="(_, i) => i"