Open idesignzone opened 11 months ago
I have trouble getting the new array list. here is my code
<template> <div> <Sortable :list="elements" item-key="id" tag="div" :options="options" @change="DragableData($event)"> <template #item="{ element, index }"> <div :key="element.id"> {{ index }} - {{ element.name }} </div> </template> </Sortable> </div> </template> <script setup> const elements = [ { id: "1", name: "one" }, { id: "2", name: "two" }, { id: "3", name: "three" }, { id: "4", name: "four" }, ]; const options = {sort: true}; function DragableData(data) { console.log(data) } </script>
data here does not have any array in it. is it possible to get new array?
I did the following on the Sortable element I added: @end="(event) => onEnd(event)"
@end="(event) => onEnd(event)"
Then the onEnd function:
function onEnd(event) { array.splice(event.newIndex, 0, array.splice(event.oldIndex, 1)[0]); }
I have trouble getting the new array list. here is my code
data here does not have any array in it. is it possible to get new array?