npm install sortablejs --save
<a-table ref="dragTable" :data-source="newData">
</a-table>
import Sortable from "sortablejs";
mounted() {
this.$nextTick(() => this.setDrag());
},
methods: {
setDrag() {
const el = this.$refs.dragTable.$el.querySelectorAll(".ant-table-body > table > tbody")[0];
this.sortable = Sortable.create(el, {
ghostClass: "sortable-ghost",
setData: function (dataTransfer) {
dataTransfer.setData("Text", "");
},
onEnd: (evt) => {
const targetRow = this.newData.splice(evt.oldIndex, 1)[0];
this.newData.splice(evt.newIndex, 0, targetRow);
this.$message.success("操作成功");
},
});
},
add() {
this.$nextTick(() => this.setDrag());
},
}