console
new Vue({
el: '#app',
data: {
lists: ['1: apple', '2: banana', '3: orange', '4: melon']
},
methods: {
allowDrop(e){
e.preventDefault();
},
dragStart(e, index){
let tar = e.target;
e.dataTransfer.setData('Text', index);
if (tar.tagName.toLowerCase() == 'li') {
}
},
drop(e, index){
this.allowDrop(e);
let arr = this.lists.concat([]),
dragIndex = e.dataTransfer.getData('Text');
temp = arr.splice(dragIndex, 1);
arr.splice(index, 0, temp[0]);
this.lists = arr;
}
}
})
<transition-group id='app' name="drog" tag="ul">
<li draggable="true" v-for="(item, index) in lists" @dragstart="dragStart($event, index)"
@dragover="allowDrop" @drop="drop($event, index)" v-bind:key="item">
{{item}}
</li>
</transition-group>
ul {
min-height: 100px;
width: 200px;
margin: 20px auto;
background: #eee;
}
li {
min-height: 2em;
margin-top: 10px;
background: #abcded;
}
.drog-move {
transition: transform 1s;
}