Vue Draggable in Draggable & How to Get Parent’s Element?

This guide helps you implement nested Vue Draggable lists and access the parent container element during drag operations using simple JavaScript techniques.

When building complex UIs with drag-and-drop functionality and nesting draggable components, this is a common use case. This guide will show you how to use Vue Draggable within another and get the parent DOM element.

How to Nest Vue Draggable Components

Vue Draggable (based on Sortable.js) allows nesting with independent lists. Here’s an example:
<template>  <draggable v-model="sections" group="sections">    <template #item="{ element }">       <div class="section">         <draggable v-model="element.items" group="items">           <template #item="{ element }">             <div class="item">{{ element.name }}</div>           </template>         </draggable>       </div>     </template>   </draggable> </template>
In this structure:
  • sections is an array of section objects.
  • Each section has its own items list.
  • Both draggable elements operate in their own scope.

How to Get the Parent Element During Drag

You can get the parent element using the @start, @change, or @end event hooks provided by Vue Draggable.
<draggable   v-model="items"    @start="onStart"> </draggable>   <script> methods: {   onStart(event) {     const draggedEl = event.item; // dragged element     const parentEl = draggedEl.closest('.section'); // parent container     console.log('Parent Element:', parentEl);   } } </script>

Notes

  • Use closest() for more flexible DOM traversal.
  • Make sure parent containers have meaningful class names like .section or .wrapper.
Also Read: Why Enterprises are Choosing Vue.js for their Large-Scale Projects?

Tips

  • Give parent containers unique class names for easy targeting.
  • Use closest() instead of chaining parentElement calls.
  • Don’t manipulate the DOM directly in deeply nested components unless necessary.
  • Keep inner and outer list logic separate.

Conclusion

Nesting Vue Draggable is powerful for layered UIs. Accessing the parent element during drag events is straightforward using DOM traversal with event.item.

Related Resources

Related
Vue

In Vue 3's Composition API, watching for prop changes is essential when you need to respond to updated values passed from a parent component. Unlike…

23 Oct, 2025
Vue

Why You See "Vue is Not a Constructor" This error usually occurs when you're trying to use new Vue() to create an instance, but: Vue…

15 Oct, 2025
Vue

Vue encourages reactive and declarative programming for maintainability. But sometimes direct DOM access is required. In those cases, the $el property gives you access to…

10 Oct, 2025