vuedraggable实现列表拖动排序
程序员文章站
2022-04-25 16:50:09
...
安装
npm i -S vuedraggable
页面进行导入
import draggable from "vuedraggable";
完整代码效果
<template>
<div class="box">
<draggable v-model="list" chosenClass="active" animation="500" @end="dragEnd">
<div class="row" v-for="(item,index) in list" :key="index">{{item}}</div>
</draggable>
</div>
</template>
<script>
import draggable from "vuedraggable";
export default {
components: {
draggable
},
data() {
return {
list: [1, 2, 3, 4, 5, 6, 7]
};
},
methods: {
dragEnd() {
console.log(this.list);
}
}
};
</script>
<style scoped>
.row {
background: cadetblue;
width: 100%;
height: 150px;
line-height: 150px;
text-align: center;
margin: 15px 0;
}
.active {
background: chocolate !important;
}
</style>