1、定义好拖拽元素 ref标识,以及 row-key="id"  (row-key拖拽标识,拖拽后数据不会乱, id为tableDataNew数据对象id)

2、下载cnpm install sortablejs --save 插件,并引入 import Sortable from 'sortablejs'

3、nextTixk触发

this.$nextTick(() => {
     this.rowDrop();
})
4、行拖拽
rowDrop() {
            const tbody = this.$refs.manufacturing.$el.querySelector(
                ".el-table__body-wrapper > table > tbody"
            );
            const _this = this;
            Sortable.create(tbody, {
                onEnd({ newIndex, oldIndex }) {
                    const currRow = _this.tableDataNew.splice(oldIndex, 1)[0];
                    _this.tableDataNew.splice(newIndex, 0, currRow);
                },
            });
        },
posted on 2023-02-15 13:24  热心市民宗某§  阅读(147)  评论(0编辑  收藏  举报