Search code examples
vue.jsvue.draggable

Access property in Vue Draggable move method


How can I in the method access the properties of the item belonging to the moved element? I know evt.item.id is not working...

<draggable v-model="myarray" :move="onMove">
<div v-for="item in myarray" :key="item.id">

...

methods: {
onMove(evt){
     console.log(evt.item.id)
}

Solution

  • item that you use is only variable name that you use in v-for. You need to access draggedContext.element for this:

    methods: {
        onMove(evt) {
            console.log(evt.draggedContext.element.id)
        }
    }