本文实例为大家分享了vue.draggable实现表格拖拽排序效果展示的具体代码,供大家参考,具体内容如下
主要使用vuedraggable和sortablejs两个组件。
1、安装组件
npm install vuedraggable npm install sortablejs
2、引入组件
import draggable from 'vuedraggable'; import Sortable from 'sortablejs'; export default { components: { draggable, Sortable }, ....
3、HTML
我的例子是给表格排序,项目整体使用的是ivew,所以用了ivew的栅格来画表格
<Row class="draggableTable-head"> <Col span="1">序号</Col> <Col span="2">商品条码</Col> <Col span="3">商品名称</Col> <Col span="1">单位</Col> </Row> <draggable class="list-group" v-model="tableData" :options="{draggable:'.rows'}" :move="getdata" @update="datadragEnd"> <Row class="rows" v-for="(item,index) in tableData" :key="index"> <Col span="1"> <div class="cell">{{index+1}}</div> </Col> <Col span="2"> <div class="cell">{{item.barCode}}</div> </Col> <Col span="2"> <div class="cell">{{item.name}}</div> </Col> <Col span="2"> <div class="cell">{{item.unit}}</div> </Col> </Row> </draggable>
options中draggable的值是拖动的class。一开始怎么都不能拖动,加上这个就可以了。
4、两个方法
move:拖动中
update:拖拽结束
getdata (data) { // console.log('getdata方法'); }, datadragEnd (evt) { // console.log('datadragEnd方法'); console.log('拖动前的索引 :' + evt.oldIndex) console.log('拖动后的索引 :' + evt.newIndex) }
表格的处理逻辑是:
1、当前行的id和排序号作为参数,调用后台更改顺序的方法
2、不论调用成功与否,都重新渲染表格数据
【注意】如果有分页,那么传给后台的排序号就要再加上之前的条数,即(页码-1)*每页条数
Vue.Draggable作者的git地址
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
风云阁资源网 Design By www.bgabc.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
风云阁资源网 Design By www.bgabc.com
暂无评论...
更新日志
2024年09月23日
2024年09月23日
- 周冰倩1995《沧桑情歌》JVC日本录制[WAV+CUE]
- 辛禄乐队.2024-热烈的少年【星辰】【FLAC分轨】
- 成龙.1996-龙的心【滚石】【WAV+CUE】
- 童安格.1991-一世情缘【宝丽金】【WAV+CUE】
- 韩红2010-擦肩而过[央金玛][WAV+CUE]
- RiccardoTesi-UnballoLiscio,Vol.II(2024)[24-48]FLAC
- 金池VS刘罡2009《双声情》[WAV+CUE]
- 冯奥迪《卄》[320K/MP3][67.08MB]
- 冯奥迪《卄》[FLAC/分轨][172.46MB]
- Merryland《Merryland》[320K/MP3][69.48MB]
- 苏芮.1991-停在我心里的温柔【福茂】【WAV+CUE】
- 苏慧伦.2020-面面Every.Side.of.Me【相信音乐】【WAV+CUE】
- 群星.1991-不一样的感觉REMIX【宝丽金】【WAV+CUE】
- 银霞.1983-《你那好冷的小手》珍藏纪念版[WAV分轨]
- 银霞.2002-《国语巨星专辑VOL.3》2CD台湾版[WAV+CUE]