0

How can I use VueDraggable to clone an item that once cloned has no link to the original item.

Please take this fiddle as an example: https://jsfiddle.net/32f7yu7c/69/

When you drag an item from list 1 to list 2, please hit the 'update' text and you'll see both names in both lists are updated. How can i prevent this behaviour?

What I would like is this click handler <span @click="update(index)">Update</span> is triggered you update only the item in the relative list.

0

1 Answer 1

1

By default, VueDraggable doesn't actually make a deep clone. You need to add a 'clone' property to your draggable component, with the name of your clone method:

<draggable :list="list" class="dragArea" :clone="clone" :options="{group:{ name:'people',  pull:'clone', put:false }}">

and add the clone method to your component:

clone: function(me) {
   return JSON.parse(JSON.stringify(me));
}

Here's a working fiddle:

https://jsfiddle.net/jmbldwn/3gcyemft/1/

Sign up to request clarification or add additional context in comments.

4 Comments

I literally love you. Thanks!
Best reaction I've ever gotten :-). You're welcome.
Out of curiosity why do we have to do this?
It's the safe choice. Some use cases may not want to make copies automatically.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.