Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.86 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Drag vue items</title>
  6. <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
  7.  
  8. <style>
  9. .wrapper {
  10. margin: 0 auto;
  11. max-width: 400px;
  12. }
  13.  
  14. .list-items__ul {
  15. max-width: 300px;
  16. list-style-type: none;
  17. margin: 0;
  18. padding: 0;
  19. }
  20.  
  21. .list-item__title {
  22. display: block;;
  23. padding: 10px;
  24. border-radius: 5px;
  25. background: gray;
  26. border: none;
  27. color: white;
  28. }
  29.  
  30. .list-item {
  31. margin-top: 10px;
  32. display: block;
  33. }
  34.  
  35. .list-item > ul {
  36. margin-left: 15px;
  37. }
  38.  
  39. .list-item.placeholder {
  40. border: none;
  41. background: #d1fffd;
  42. opacity: 0.5;
  43. border-radius: 5px;
  44. }
  45.  
  46. .list-item.dragging .list-item__title {
  47. background: blue;
  48. }
  49.  
  50. .list-item.drag-over .list-item__title {
  51. background: green;
  52. }
  53.  
  54. .list-item__handle_drag {
  55. display: inline-block;
  56. float: right;
  57. padding: 2px 5px;
  58. cursor: all-scroll;
  59. }
  60.  
  61. </style>
  62. </head>
  63. <body>
  64.  
  65. <div class="wrapper">
  66. <div id="app">
  67. <h1>{{ message }}</h1>
  68. <list-dragable
  69. :list-items="listItems">
  70. </list-dragable>
  71. </div>
  72. </div>
  73.  
  74. <script src="https://unpkg.com/vue"></script>
  75.  
  76. <script type="text/x-template" id="item-dragable-template">
  77. <li class="list-item list-item__dragable">
  78. <div class="list-item__title">
  79. {{model.text}}
  80. <div class="list-item__handle_drag">
  81. <i class="fa fa-bars" aria-hidden="true"></i>
  82. </div>
  83. </div>
  84. <ul class="list-items__ul" v-if="model.children !== undefined && model.children.length > 0">
  85. <item-dragable
  86. v-for="item in model.children"
  87. :model="item">
  88. </item-dragable>
  89. </ul>
  90. </li>
  91. </script>
  92.  
  93. <script type="text/x-template" id="list-dragable-template">
  94. <div class="list-items">
  95. <ul class="list-items__ul">
  96. <item-dragable
  97. v-for="item in listItems"
  98. :model="item">
  99. </item-dragable>
  100. </ul>
  101. </div>
  102. </script>
  103.  
  104. <script>
  105. var data = [{
  106. text: 'My Tree',
  107. children: [
  108. {text: 'hello'},
  109. {text: 'wat'},
  110. {
  111. text: 'child folder',
  112. children: [
  113. {
  114. text: 'child folder',
  115. children: [
  116. {text: 'hello'},
  117. {text: 'wat'}
  118. ]
  119. },
  120. {text: 'hello'},
  121. {text: 'wat'},
  122. {
  123. text: 'child folder',
  124. children: [
  125. {text: 'hello'},
  126. {text: 'wat'}
  127. ]
  128. }
  129. ]
  130. }
  131. ]
  132. }];
  133.  
  134. Vue.component('itemDragable', {
  135. template: '#item-dragable-template',
  136. props: {
  137. model: Object
  138. }
  139. });
  140.  
  141. Vue.component('listDragable', {
  142. template: '#list-dragable-template',
  143. props: {
  144. listItems: Object
  145. }
  146. });
  147.  
  148. // boot up the demo
  149. var demo = new Vue({
  150. el: '#app',
  151. data: function () {
  152. return {
  153. listItems: data
  154. }
  155. }
  156. })
  157. </script>
  158. </body>
  159. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement