/
AddItem.vue
94 lines (89 loc) · 1.81 KB
/
AddItem.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
<template>
<ComponentExample link="AddItem">
<VueNestable v-model="nestableItems">
<VueNestableHandle slot-scope="{ item }" :item="item">
<i class="fas fa-user" />
{{ item.text }}
</VueNestableHandle>
<template slot="footer" slot-scope="{ item, index }">
<div class="add-item">
<a @click="addRow(item, index)">
<i class="fas fa-plus" /> Add item
</a>
</div>
</template>
</VueNestable>
</ComponentExample>
</template>
<script>
import ComponentExample from "./ComponentExample.vue";
export default {
components: {
ComponentExample
},
data() {
return {
nestableItems: [
{
id: 0,
text: "Andy"
},
{
id: 1,
text: "Harry",
children: [
{
id: 2,
text: "David",
children: [
{
id: 11,
text: "Davids child",
children: []
}
]
},
{
id: 10,
text: "Davids brother",
children: []
}
]
},
{
id: 3,
text: "Nicole"
}
]
};
},
methods: {
addRow(row, index) {
row.children.push({
id: "new" + Math.floor(Math.random() * Math.floor(10000)),
text: "New item",
children: []
});
}
}
};
</script>
<style scoped>
.add-item::before {
content: " ";
border: 5px solid #959eb1;
border-radius: 100%;
position: absolute;
top: -6px;
left: -6px;
}
.add-item {
position: relative;
margin: 0.5rem 0;
padding: 0.5rem;
border: 1px solid #959eb1;
border-top: 3px solid #959eb1;
border-radius: 6px;
background: #f9fafb;
}
</style>