forked from woai3c/visual-drag-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComponentList.vue
73 lines (65 loc) · 1.53 KB
/
ComponentList.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
<template>
<div class="component-list" @dragstart="handleDragStart">
<div
v-for="(item, index) in componentList"
:key="index"
class="list"
draggable
:data-index="index"
>
<span v-if="item.icon.substr(0,2) === 'el'" :class="item.icon"></span>
<span v-else class="iconfont" :class="'icon-' + item.icon"></span>
</div>
</div>
</template>
<script>
import componentList from '@/custom-component/component-list'
export default {
data() {
return {
componentList,
}
},
methods: {
handleDragStart(e) {
e.dataTransfer.setData('index', e.target.dataset.index)
},
},
}
</script>
<style lang="scss" scoped>
.component-list {
height: 65%;
padding: 10px;
display: grid;
grid-gap: 10px 19px;
grid-template-columns: repeat(auto-fill, 80px);
grid-template-rows: repeat(auto-fill, 40px);
.list {
width: 80px;
height: 40px;
border: 1px solid #ddd;
cursor: grab;
text-align: center;
color: #333;
padding: 2px 5px;
display: flex;
align-items: center;
justify-content: center;
&:active {
cursor: grabbing;
}
.iconfont {
margin-right: 4px;
font-size: 20px;
}
.icon-wenben,
.icon-biaoge {
font-size: 18px;
}
.icon-tupian {
font-size: 16px;
}
}
}
</style>