1. Download the package: npm install vuedraggable
Configuration: package.json
"dependencies": { "vuedraggable": "^2.11.0" },
2. introduction rely on your components:
import draggable from 'vuedraggable'
3. Registration: draggable This component
components: { draggable },
4. Use html template used in the assembly
<draggable v-model="tags" :move="getdata" @update="datadragEnd">
<transition-group>
<div v-for="element in tags" :key="element.id"> {{element.name}} </div>
</transition-group>
</draggable>
5. There are two common methods
One is in drag
One is the drag ends
methods: {
getdata (evt) {
console.log(evt.draggedContext.element.id)
},
datadragEnd (evt) {
console.log('拖动前的索引 :' + evt.oldIndex)
console.log('拖动后的索引 :' + evt.newIndex)
console.log(this.tags)
}
}