npm i sortablejs
import Sortable from "sortablejs";
//表格拖动排序
async dragSort() {
const el = this.$refs.singleTable.$el.querySelectorAll(".el-table__body-wrapper > table > tbody")[0];
this.sortable = Sortable.create(el, {
ghostClass: "sortable-ghost",
setData: function (dataTransfer) {
dataTransfer.setData("Text", "");
},
onEnd: (e) => {
//e.oldIndex为拖动一行原来的位置,e.newIndex为拖动后新的位置
const targetRow = this.table_liexiang2.splice(e.oldIndex, 1)[0];
this.table_liexiang2.splice(e.newIndex, 0, targetRow);
},
});
},
//打开dialog
async liexiang_button(type) {
this.get_column(type);
this.liexiang_dialog = true;
this.$nextTick(() => {
this.dragSort();
});
},
vue elementui 表格拖动排序
最新推荐文章于 2025-04-28 23:55:19 发布