elementUi table表格的拖拽功能

引入:  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);
}
 
 

 

posted @ 2021-06-07 15:10  鬼鬼丶  阅读(510)  评论(0编辑  收藏  举报