Vue.Draggable drag effect

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) 
    } 
}

 

Published 106 original articles · won praise 47 · views 130 000 +

Guess you like

Origin blog.csdn.net/qq493820798/article/details/104396364