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
| <template> <div class="listAll"> <transition-group name="drag" class="list" tag="ul"> <li @dragenter="dragenter($event, index)" @dragover="dragover($event, index)" @dragstart="dragstart($event,index)" draggable="true" v-for="(item, index) in list" :key="item.title" :id="item.id" class="list-item el-dropdown-menu__item" @click="dataLink(item)" :class="{isactive:dragId===item.id}" > <div> {{ item.title }} </div> <div style="font-size: 8px"> {{item.link_sum}} </div> </li> </transition-group> </div> </template>
<script>
export default { name:'list', props:{ list:[] }, data() { return { dragIndex: "", enterIndex: "", dragId:"", }; }, methods: { //关于拖拽的函数 dragstart(e,index) { this.dragIndex = index; }, dragenter(e, index) { e.preventDefault(); if (this.dragIndex !== index) { const moving = this.list[this.dragIndex]; this.list.splice(this.dragIndex, 1); this.list.splice(index, 0, moving); this.dragIndex = index; } }, dragover(e, index) { // this.selectId = this.dragId e.preventDefault(); }, dataLink(val){ //点击样式 this.dragId = val.id //点了就传给vuex,得到这组数据,数据里有id链接数等等 this.$store.state.group = val } } }; </script> <style scoped> .listAll{ height: 100%; } .list { margin: 0; list-style: none; padding-left: 0; border: 0;
} .drag-move { transition: transform 0.3s; } .list-item { cursor: pointer; width:100%; line-height: 50px; text-align: center; padding: 0 !important; display: flex; justify-content: space-around; } .isactive{ background-color: rgb(236, 245, 255); } </style>
|