引入: import Sortable from 'sortablejs';
声明: sortable: any = null;
初始化:
mounted() { const targetDom = this.$refs.table; this.sortable = new Sortable(targetDom, { onEnd: this.onEnd }); }
@Emit('drap')
onEnd({ oldIndex, newIndex }) {
return {
oldIndex: oldIndex,
newIndex: newIndex
};
}
逻辑处理代码:
handleDrap(index, key) {
const currRow = this.data[key].splice(index.oldIndex, 1)[0];
this.data[key].splice(index.newIndex, 0, currRow);
}