-
Notifications
You must be signed in to change notification settings - Fork 545
/
Copy pathsimple.vue
103 lines (96 loc) · 2.16 KB
/
simple.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<template>
<div class="row">
<div class="col-2">
<div class="form-group">
<div
class="btn-group-vertical buttons"
role="group"
aria-label="Basic example"
>
<button class="btn btn-secondary" @click="add">Add</button>
<button class="btn btn-secondary" @click="replace">Replace</button>
</div>
<div class="form-check">
<input
id="disabled"
type="checkbox"
v-model="enabled"
class="form-check-input"
/>
<label class="form-check-label" for="disabled">DnD enabled</label>
</div>
</div>
</div>
<div class="col-6">
<h3>Draggable {{ draggingInfo }}</h3>
<draggable
:list="list"
:disabled="!enabled"
item-key="name"
class="list-group"
ghost-class="ghost"
:move="checkMove"
@start="dragging = true"
@end="dragging = false"
>
<template #item="{ element }">
<div class="list-group-item" :class="{ 'not-draggable': !enabled }">
{{ element.name }}
</div>
</template>
</draggable>
</div>
<rawDisplayer class="col-3" :value="list" title="List" />
</div>
</template>
<script>
import draggable from "@/vuedraggable";
let id = 1;
export default {
name: "simple",
display: "Simple",
order: 0,
components: {
draggable
},
data() {
return {
enabled: true,
list: [
{ name: "John", id: 0 },
{ name: "Joao", id: 1 },
{ name: "Jean", id: 2 }
],
dragging: false
};
},
computed: {
draggingInfo() {
return this.dragging ? "under drag" : "";
}
},
methods: {
add: function() {
this.list.push({ name: "Juan " + id, id: id++ });
},
replace: function() {
this.list = [{ name: "Edgard", id: id++ }];
},
checkMove: function(e) {
window.console.log("Future index: " + e.draggedContext.futureIndex);
}
}
};
</script>
<style scoped>
.buttons {
margin-top: 35px;
}
.ghost {
opacity: 0.5;
background: #c8ebfb;
}
.not-draggable {
cursor: no-drop;
}
</style>