DragList.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <section class="main">
  3. <div class="crumbs">
  4. <el-breadcrumb separator="/">
  5. <el-breadcrumb-item><i class="el-icon-rank"></i> 拖拽组件</el-breadcrumb-item>
  6. <el-breadcrumb-item>拖拽排序</el-breadcrumb-item>
  7. </el-breadcrumb>
  8. </div>
  9. <div class="container">
  10. <div class="plugins-tips">
  11. Vue.Draggable:基于 Sortable.js 的 Vue 拖拽组件。
  12. 访问地址:<a href="https://github.com/SortableJS/Vue.Draggable" target="_blank">Vue.Draggable</a>
  13. </div>
  14. <div class="drag-box">
  15. <div class="drag-box-item">
  16. <div class="item-title">todo</div>
  17. <draggable v-model="todo" @remove="removeHandle" :options="dragOptions">
  18. <transition-group tag="div" id="todo" class="item-ul">
  19. <div v-for="item in todo" class="drag-list" :key="item.id">
  20. {{item.content}}
  21. </div>
  22. </transition-group>
  23. </draggable>
  24. </div>
  25. <div class="drag-box-item">
  26. <div class="item-title">doing</div>
  27. <draggable v-model="doing" @remove="removeHandle" :options="dragOptions">
  28. <transition-group tag="div" id="doing" class="item-ul">
  29. <div v-for="item in doing" class="drag-list" :key="item.id">
  30. {{item.content}}
  31. </div>
  32. </transition-group>
  33. </draggable>
  34. </div>
  35. <div class="drag-box-item">
  36. <div class="item-title">done</div>
  37. <draggable v-model="done" @remove="removeHandle" :options="dragOptions">
  38. <transition-group tag="div" id="done" class="item-ul">
  39. <div v-for="item in done" class="drag-list" :key="item.id">
  40. {{item.content}}
  41. </div>
  42. </transition-group>
  43. </draggable>
  44. </div>
  45. </div>
  46. </div>
  47. </section>
  48. </template>
  49. <script>
  50. import draggable from 'vuedraggable'
  51. export default {
  52. name: 'draglist',
  53. data() {
  54. return {
  55. dragOptions:{
  56. animation: 120,
  57. scroll: true,
  58. group: 'sortlist',
  59. ghostClass: 'ghost-style'
  60. },
  61. todo: [
  62. {
  63. id: 1,
  64. content: '开发图表组件'
  65. },
  66. {
  67. id: 2,
  68. content: '开发拖拽组件'
  69. },
  70. {
  71. id: 3,
  72. content: '开发权限测试组件'
  73. }
  74. ],
  75. doing: [
  76. {
  77. id: 1,
  78. content: '开发登录注册页面'
  79. },
  80. {
  81. id: 2,
  82. content: '开发头部组件'
  83. },
  84. {
  85. id: 3,
  86. content: '开发表格相关组件'
  87. },
  88. {
  89. id: 4,
  90. content: '开发表单相关组件'
  91. }
  92. ],
  93. done:[
  94. {
  95. id: 1,
  96. content: '初始化项目,生成工程目录,完成相关配置'
  97. },
  98. {
  99. id: 2,
  100. content: '开发项目整体框架'
  101. }
  102. ]
  103. }
  104. },
  105. components:{
  106. draggable
  107. },
  108. methods: {
  109. removeHandle(event){
  110. console.log(event);
  111. this.$message.success(`从 ${event.from.id} 移动到 ${event.to.id} `);
  112. }
  113. }
  114. }
  115. </script>
  116. <style scoped>
  117. .drag-box{
  118. display: flex;
  119. user-select: none;
  120. }
  121. .drag-box-item {
  122. flex: 1;
  123. max-width: 330px;
  124. min-width: 300px;
  125. background-color: #eff1f5;
  126. margin-right: 16px;
  127. border-radius: 6px;
  128. border: 1px #e1e4e8 solid;
  129. }
  130. .item-title{
  131. padding: 8px 8px 8px 12px;
  132. font-size: 14px;
  133. line-height: 1.5;
  134. color: #24292e;
  135. font-weight: 600;
  136. }
  137. .item-ul{
  138. padding: 0 8px 8px;
  139. height: 500px;
  140. overflow-y: scroll;
  141. }
  142. .item-ul::-webkit-scrollbar{
  143. width: 0;
  144. }
  145. .drag-list {
  146. border: 1px #e1e4e8 solid;
  147. padding: 10px;
  148. margin: 5px 0 10px;
  149. list-style: none;
  150. background-color: #fff;
  151. border-radius: 6px;
  152. cursor: pointer;
  153. -webkit-transition: border .3s ease-in;
  154. transition: border .3s ease-in;
  155. }
  156. .drag-list:hover {
  157. border: 1px solid #20a0ff;
  158. }
  159. .drag-title {
  160. font-weight: 400;
  161. line-height: 25px;
  162. margin: 10px 0;
  163. font-size: 22px;
  164. color: #1f2f3d;
  165. }
  166. .ghost-style{
  167. display: block;
  168. color: transparent;
  169. border-style: dashed
  170. }
  171. </style>