<el-table
ref="dragTable"
:data="tableData"
height="500"
border
row-key="id"
highlight-current-row
style="width: 100%"
></el-table>
mounted () { // 页面进入时加载内容
this.setSort();
},
methods: {
setSort(){
const el = this.$refs.dragTable.$el.querySelectorAll('.el-table__body- wrapper > table > tbody')[0]
this.sortable = Sortable.create(el, {
ghostClass: 'sortable-ghost',
setData: function(dataTransfer){
dataTransfer.setData('Text', '')
},
onEnd: evt => {
const targetRow = this.tableData.splice(evt.oldIndex, 1)[0];
this.tableData.splice(evt.newIndex, 0, targetRow);
this.tableData.forEach((item, idx) => {
item.orderNumber = idx
})
this.updateAllData()
}
})
},
}