拖拽
作者:互联网
1. 插件地址
https://www.itxst.com/vue-draggable/tutorial.html
配合element 的table
<template> <div> <el-table :data="tableData" style="width: 100%" row-key="id"> <el-table-column prop="date" label="日期" width="180"> </el-table-column> <el-table-column prop="name" label="姓名" width="180"> </el-table-column> <el-table-column prop="address" label="地址"> </el-table-column> </el-table> </div> </template> <script> import Sortable from "sortablejs"; export default { data() { return { tableData: [ { id:1, date: "2016-05-01", name: "王小虎", address: "上海市普陀区金沙江路 1518 弄", }, { id:2, date: "2016-05-02", name: "王小虎", address: "上海市普陀区金沙江路 1517 弄", }, { id:3, date: "2016-05-03", name: "王小虎", address: "上海市普陀区金沙江路 1519 弄", }, { id:4, date: "2016-05-04", name: "王小虎", address: "上海市普陀区金沙江路 1516 弄", }, ], data: [], }; }, methods: { // 拖动 Mydrag() { // 首先获取需要拖拽的dom节点 const el1 = document .querySelectorAll(" .el-table__body-wrapper")[0] .querySelectorAll("table > tbody")[0]; Sortable.create(el1, { disabled: false, // 是否开启拖拽 ghostClass: "sortable-ghost", //拖拽样式 // animation: 150, // 拖拽延时,效果更好看 group: { // 是否开启跨表拖拽 pull: false, put: false, }, onEnd: (e) => { // 这里主要进行数据的处理,拖拽实际并不会改变绑定数据的顺序,这里需要自己做数据的顺序更改 let arr = this.tableData; // 获取表数据 arr.splice(e.newIndex, 0, arr.splice(e.oldIndex, 1)[0]); // 数据处理 this.$nextTick(function () { this.tableData = arr; }); }, }); }, }, mounted(){ this.Mydrag() } }; </script> <style scoped> .sortable-ghost { opacity: 1; cursor: move; background-color: red; } ::v-deep .el-table__row{ cursor: move; } </style>
标签:name,05,普陀区,王小虎,2016,拖拽 来源: https://www.cnblogs.com/czwhandsome/p/16502376.html