Open vedmant opened 1 year ago
Same problema here. Imagine you need to make an array of string sortable, you cannot because you dont have any field to provide as item-key. You can set a callback in the item-key property, but then you have access to the item but not to the index, so you cannot provide anything unique as a key. Ther must be a simple way to access the element index or use the index as item-key as you could before in versión 2.
Like @Alhubing mentioned, you can set a callback-function as item-key and use it to get the index of the item or just return the String itself.
have a look at this pen: https://codepen.io/3m7ecc/pen/GRBxqBm
I'd love to know if anyone else figured this out. Like what if you have items that are duplicates? The second solution wouldn't work at all.
several points:
:item-key="() => ++someLocalVar"
(causes unnecessary rendering, but who cares)
2.2. making the key fixed, i.e. :item-key="() => 42"
(both works for me)...
<template #item="{element}">
<input v-model="element">
...
does not work - my "solution" is to wrap my strings into an object such that <input v-model="element.text">
works. Any other ideas?
In my component in some cases I have no information what possible attributes object will have, in this case I can only use index as a key, but how it's now can be achieved, with Vue 2 I had no problems with it. But currently with new approach when Draggable is iterating instead of me caused a problem. And generally this is terrible idea to iterate arrays instead of users, what if it's not an array even should be iterated.