安装、引入sortablejs插件
npm install sortablejs -S
import Sortable from 'sortablejs'
排序方法
setSort () {
const el = this.$refs.grid.$el.querySelectorAll('.el-table__body-wrapper > table > tbody')[0]
const _this = this
Sortable.create(el, {
onEnd({ newIndex, oldIndex }) {
const currRow = _this.list.splice(oldIndex, 1)[0]
_this.list.splice(newIndex, 0, currRow)
}
})
},
el-table注意事项
需要加上row-key="id", 否则会错乱