UNPKG

cnetong-core-frontend

Version:

## 1. 开始使用 ```js // 在npm项目中的main.js文件中加入以下代码 import Base from "cnetong-core-frontend";

27 lines (22 loc) 738 B
import Sortable from "sortablejs"; let VelTableSort = { bind(el, binding, vnode, oldnode) { const tbody = el.querySelectorAll(".el-table__body-wrapper > table > tbody")[0]; const orderKey = binding.arg; Sortable.create(tbody, { ghostClass: "sortable-ghost", chosenClass: "sortable-chosen", animation: 150, setData: function (dataTransfer) { dataTransfer.setData("Text", ""); }, onEnd({newIndex, oldIndex}) { const data = vnode.componentInstance.data; const targetRow = data.splice(oldIndex, 1)[0]; data.splice(newIndex, 0, targetRow); data.forEach((item, idx) => (item[orderKey] = idx + 1)); } }); } }; export default VelTableSort;