Alfred-Skyblue / vue-draggable-plus

Universal Drag-and-Drop Component Supporting both Vue 3 and Vue 2
https://vue-draggable-plus.pages.dev/en/
MIT License
2.72k stars 106 forks source link

nested-component doesn't work #67

Closed desousar closed 6 months ago

desousar commented 7 months ago

Thanks for proposing an alternative to vuedraggable on Vue3 !

Situation: I have a card list. Some cards may contain other cards. This is the same behavior you illustrated in your demo (https://alfred-skyblue.github.io/vue-draggable-plus/en/demo/nested/).

I've reproduced the same basic example in my application, but the list isn't rendered.

VueDraggable alone works correctly, but not with nested-component

My application: Vue 3, currently in Option API (migration to composition API to come). I run it in google chrome. "vue": "^3.3.9", "vue-draggable-plus": "^0.3.0",

<VueDraggable tag="ul" v-model="lista" group="g1">
    <li v-for="el in modelValue" :key="el.name">
      <p>{{ el.name }}</p>
      <nested-component v-model="el.children" />
    </li>
  </VueDraggable>

data() {
  return {
    lista: [
        {
          name: 'item 1',
          children: [
            {
              name: 'item 2',
              children: [],
            },
          ],
        },
        {
          name: 'item 3',
          children: [
            {
              name: 'item 4',
              children: [],
            },
          ],
        },
        {
          name: 'item 5',
          children: [],
        },
      ],
  }
}
Alfred-Skyblue commented 7 months ago

Ensure there is a default height when children.length is 0; otherwise, the drag-and-drop may not find the target element.

desousar commented 7 months ago

Ok I added the class class="drag-area" to VueDraggable and I change v-model with :list

<VueDraggable class="drag-area" tag="ul" v-model="lista" group="g1">
  <li v-for="el in lista" :key="el.name">
    <p>{{ el.name }}</p>
    <nested-component v-model="el.children" />
  </li>
</VueDraggable>

import { VueDraggable } from 'vue-draggable-plus';

I use the same data lista

.drag-area {
  min-height: 50px;
  outline: 1px dashed;
}

With <nested-component v-model="el.children" />

result: image

browser inspector: image

Am I doing something wrong with the nested-component ?

Alfred-Skyblue commented 7 months ago

This is a recursive component; if nesting is required, you need to recursively call itself.

image
desousar commented 6 months ago

Oh.... yes..... I just didn't pay attention to the detail. Indeed, it works much better now!

Thank you !!!!