Closed Ericlm closed 1 year ago
You need nextTick(), see https://github.com/vueuse/vueuse/blob/main/packages/integrations/useSortable/index.md#tips
Thank you, it works now ! This precision should be in the website's documentation I think 🙂
This is still happening!
https://codesandbox.io/p/sandbox/test-vueuse-sortable-forked-k783fk?file=%2Fsrc%2FApp.vue%3A38%2C19
This is still happening!
codesandbox.io/p/sandbox/test-vueuse-sortable-forked-k783fk?file=%2Fsrc%2FApp.vue%3A38%2C19
@Ericlm
Yeah is seems that it keeps logging only two items in the array now... Pretty strange 🤔 Anyway, I preferred to implement the reordering myself to avoid any problem with asynchronous code. This is in the doc with : // nextTick required here as moveArrayElement is executed in a microtas
but I don't really understand why. Anyway, seems easier to reorder with oldIndex
and newIndex
instead of calling moveArrayElements
.
I'll reopen the issue as there could be an easier way to handle this (making it synchronous maybe) 🙂
I am facing this problem in Nuxt. without nextTick, sortable works fine but with nextTick, result array is missing an item after drag.
useSortable(el, list, {
onUpdate: (e) => {
moveArrayElement(list.value, e.oldIndex, e.newIndex);
nextTick(() => {
console.log(list.value.map((i) => i.id));
});
},
});
"@vueuse/core": "^10.7.2",
"@vueuse/nuxt": "^10.7.2",
Describe the bug
I'm trying to use the sortable integration with
useSortable
inside a component. The reordering of HTML elements works well, however, the call tomoveArrayElement
seems buggy:As you can see, there is a log before the call and there is 3 items in the array; however, after the call, only two items are appearing ; the dragged item seems to disappear.
Reproduction
https://codesandbox.io/p/sandbox/confident-mendel-6vjzsd?file=%2FREADME.md
System Info
Used Package Manager
npm
Validations