<template><div ref="sortable-wrapper"><slot /></div>
</template><script>
import sortable from 'sortablejs';export default {props: {handle: { type: String,default: ''},data: { type: Array,default: () => ([])},},mounted() {this.initTableSortable();},methods: {initTableSortable() {const table = this.$children[0].$el.querySelector('.el-table__body-wrapper table tbody');sortable.create(table, {ghostClass: 'sortable-ghost',handle: this.handle,onStart: () => {this.$emit('drag');},onEnd: ({ newIndex, oldIndex }) => {const list = [...this.data];const targetRow = list.splice(oldIndex, 1)[0];list.splice(newIndex, 0, targetRow);this.$emit('drop', { targetRow, list });}});},}
};
</script>