|
| 1 | +<template> |
| 2 | + <div> |
| 3 | + <div class="row"> |
| 4 | + <div class="col"> |
| 5 | + <h3>Press Ctrl to clone element from list 1</h3> |
| 6 | + </div> |
| 7 | + </div> |
| 8 | + <div class="row"> |
| 9 | + <div class="col-3"> |
| 10 | + <h3>Draggable 1</h3> |
| 11 | + <draggable |
| 12 | + class="dragArea list-group" |
| 13 | + :list="list1" |
| 14 | + :clone="clone" |
| 15 | + :group="{ name: 'people', pull: pullFunction }" |
| 16 | + @start="start" |
| 17 | + > |
| 18 | + <div |
| 19 | + class="list-group-item" |
| 20 | + v-for="element in list1" |
| 21 | + :key="element.id" |
| 22 | + > |
| 23 | + {{ element.name }} |
| 24 | + </div> |
| 25 | + </draggable> |
| 26 | + </div> |
| 27 | + |
| 28 | + <div class="col-3"> |
| 29 | + <h3>Draggable 2</h3> |
| 30 | + <draggable class="dragArea list-group" :list="list2" group="people"> |
| 31 | + <div |
| 32 | + class="list-group-item" |
| 33 | + v-for="element in list2" |
| 34 | + :key="element.id" |
| 35 | + > |
| 36 | + {{ element.name }} |
| 37 | + </div> |
| 38 | + </draggable> |
| 39 | + </div> |
| 40 | + |
| 41 | + <rawDisplayer class="col-3" :value="list1" title="List 1" /> |
| 42 | + |
| 43 | + <rawDisplayer class="col-3" :value="list2" title="List 2" /> |
| 44 | + </div> |
| 45 | + </div> |
| 46 | +</template> |
| 47 | + |
| 48 | +<script> |
| 49 | +import draggable from "@/vuedraggable"; |
| 50 | +let idGlobal = 8; |
| 51 | +export default { |
| 52 | + name: "clone-on-control", |
| 53 | + display: "Clone on Control", |
| 54 | + order: 4, |
| 55 | + components: { |
| 56 | + draggable |
| 57 | + }, |
| 58 | + data() { |
| 59 | + return { |
| 60 | + list1: [ |
| 61 | + { name: "Jesus", id: 1 }, |
| 62 | + { name: "Paul", id: 2 }, |
| 63 | + { name: "Peter", id: 3 } |
| 64 | + ], |
| 65 | + list2: [ |
| 66 | + { name: "Luc", id: 5 }, |
| 67 | + { name: "Thomas", id: 6 }, |
| 68 | + { name: "John", id: 7 } |
| 69 | + ], |
| 70 | + controlOnStart: true |
| 71 | + }; |
| 72 | + }, |
| 73 | + methods: { |
| 74 | + clone({ name }) { |
| 75 | + return { name, id: idGlobal++ }; |
| 76 | + }, |
| 77 | + pullFunction() { |
| 78 | + return this.controlOnStart ? "clone" : true; |
| 79 | + }, |
| 80 | + start({ originalEvent }) { |
| 81 | + this.controlOnStart = originalEvent.ctrlKey; |
| 82 | + } |
| 83 | + } |
| 84 | +}; |
| 85 | +</script> |
| 86 | +<style scoped></style> |
0 commit comments