1.下载插件 import Sortable from 'sortablejs'
2.dom元素可以获取了之后.
const table = document.querySelector('.el-table__body-wrapper tbody')
const self = this
let menutable = Sortable.create(table, {
disabled: false,
onStart(e) {
// 这里是特殊要求.如果不满足某一项条件.直接禁用插件
if (self.form.menuGroupModuleId === '') {
self.$message.warning('请选择一项菜单分组后排序')
menutable.destroy()
setTimeout(() => {
self.sorttable()
}, 1000)
}
},
async onEnd({ newIndex, oldIndex }) {
const from = self.tableData[oldIndex]
const to = self.tableData[newIndex]
try {
const response = await MenuAndUser.menusort({
from: from.itemOrder,
to: to.itemOrder,
bsm: from.bsm
})
if (response.status == 200) {
self.$message.success('菜单排序成功')
self.getmenudata()
}
} finally {
}
}
})
3.排序成功之后发起请求重新获取表格数据.给表格赋值之前先.把表格数据清空.