引入
import Sortable from 'sortablejs'
给好id
row-key="id"
mounted初始化
mounted() {
let that = this
this.rowDrop(that)
},
排序修改方法
rowDrop(that) {
const tbody = document.querySelector('.el-table__body-wrapper tbody');
const _this = this;
Sortable.create(tbody, {
onEnd({ newIndex, oldIndex }) {
console.log(newIndex+"<--"+oldIndex)
_this.updateMoveData(that,newIndex,oldIndex);
}
});
},
// 拖拽排序接口
async updateMoveData(that,newIndex,oldIndex) {
console.log(that.data[newIndex].sortNum+"<--"+that.data[oldIndex].sortNum);
this.$confirm("此操作将移动该类型, 是否继续?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "danger",
}).then(() => {
console.log("yes")
});
},