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.71k stars 106 forks source link

两层嵌套VueDraggable,内部VueDraggable组件无法响应update事件? #140

Closed ZeronoFreya closed 1 month ago

ZeronoFreya commented 1 month ago

代码只包含必要部分: 这是子组件

setup(props, {emit}) {
      const list = computed({
            get: () => props.modelValue,
            set: value => emit('update:modelValue', value)
        })
}
<template lang="pug">
VueDraggable(handle=".handle", v-model="list", @update="有效")
    .div(v-for="item in list", :key="item.id")
        .handle
        VueDraggable(v-model="item.data", group="tool", @update="无效")
            .item(v-for="val in item.data", :key="val.id") {{ val.id }}
</template>
Alfred-Skyblue commented 1 month ago

需要提供最小复现案例

ZeronoFreya commented 1 month ago

https://stackblitz.com/edit/github-b2xatc-cedu5n?file=src%2FMyDrag.vue

输出看控制台

Alfred-Skyblue commented 1 month ago

只有更改列表内排序时才会触发 onUpdate,夸列表拖动会触发 onAdd onRemove,不会触发 onUpdate

ZeronoFreya commented 1 month ago

原来如此,那请问如果我只关心数据的变化,不关心具体变化的是什么,用watch开启deep是不是更好?因为添加onAdd onRemove还需要避免两次触发

Alfred-Skyblue commented 1 month ago

不会,你同一个列表,要么触发 onAdd 要么触发 onRemove,不会同时触发,当然你用 watch 监听也可以

ZeronoFreya commented 1 month ago

感谢解答,我关闭这个话题了

zlecheng commented 1 week ago

楼主最后怎么解决这个问题的?我也遇到了

zlecheng commented 1 week ago

用更暴力的方法解决了,需要方案的留言