Vue.Draggable single

by kabanoki

HTML

<div id="app">
 <draggable tag="ul">
   <li v-for="item, index in items" :key="item.no">{{item.name}}-(No.{{item.no}})</li>
 </draggable>
</div>

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/Sortable.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Vue.Draggable/2.23.2/vuedraggable.umd.min.js"></script>

CSS

#app {
  padding : 15px;
}

li {
  cursor:pointer;
  padding: 10px;
  border: solid #ddd 1px;
}

Vue

const draggable = window['vuedraggable'];

new Vue({
  el: "#app",
  components: {
   'draggable': draggable,
  },
  data: {
    items:[
      {no:1, name:'キャベツ', categoryNo:'1'},
      {no:2, name:'ステーキ', categoryNo:'2'},
      {no:3, name:'リンゴ', categoryNo:'3'}
    ]
  }
});