Vue.Draggable icon indicating copy to clipboard operation
Vue.Draggable copied to clipboard

How to properly clone between Draggable

Open lucadegasperi opened this issue 10 years ago • 10 comments

Hello, I've got 2 draggable components, from the first one objects can be cloned into the second draggable component. The problem Arises when cloning two object of the same type because they become interlinked (and changing data on one changes the data on the other) Is there a way to do a deep clone of one item?

lucadegasperi avatar Oct 19 '16 13:10 lucadegasperi

Hello @lucadegasperi , could you provide a fiddle showing the current behaviour and explaining what you would expect? Thanks.

David-Desmaisons avatar Oct 19 '16 13:10 David-Desmaisons

Whoa, quick answer: Here's the fiddle: https://jsfiddle.net/32f7yu7c/ Try dragging one item from the list above to the list below and then click on the item in the list below. It will update the item in the list above as well (thus it's not a real cloning)

lucadegasperi avatar Oct 19 '16 13:10 lucadegasperi

I understand what you are trying to do and currently vue.draggable is designed to use the same object when the clone option is used. I think that an extra hook could be provided to let the user decide the stategy to clone the dragged element.

David-Desmaisons avatar Oct 19 '16 17:10 David-Desmaisons

Would be awesome as I'm stuck with this problem.

Even without a hook, where should I look for to properly clone the object?

lucadegasperi avatar Oct 19 '16 17:10 lucadegasperi

You should take a look at onDragAdd (evt) . That said I should provide the fix today or tomorrow.

David-Desmaisons avatar Oct 19 '16 17:10 David-Desmaisons

Guess I can wait that long :) Thanks!

lucadegasperi avatar Oct 19 '16 17:10 lucadegasperi

Added the clone props to override the current cloning behaviour. See readme for documentation of this new function and this example: https://jsfiddle.net/dede89/dcvLufju/

David-Desmaisons avatar Oct 20 '16 14:10 David-Desmaisons

这个问题困扰了老子很久很久 百度搜索搜不到 换了谷歌搜索 一下子就出来了 牛批牛批 感谢作者! Thaaaaaaaaaaaaaaks!!!!!!!!!!

Sun11l avatar May 06 '19 09:05 Sun11l

I found another pretty good example of "clone" https://codepen.io/getreworked/pen/zMzzQR?editors=1010

dhubbard-ag avatar Feb 04 '21 15:02 dhubbard-ag

https://wpconstant.com/vue-draggable-one-to-many-clone-vue3/

Pijushgupta avatar Apr 24 '22 08:04 Pijushgupta