本文最后更新于 2025-04-18T20:03:05+08:00
安装sortablejs
npm i sortablejs
vue代码
1 2 3 4 5 6
| <Table ref="zjTableRef" :dataSource="dataSource" :columns="columns" row-key="id" ></Table>
|
js代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| const zjTableRef = ref() const tbody = zjTableRef.value?.$el?.querySelector(".ant-table-tbody"); if (!tbody) return;
sortableInstance.value = Sortable.create(tbody, { animation: 150, handle: ".ant-table-row", onEnd: ({ oldIndex, newIndex }) => { if (oldIndex === newIndex) return; const [movedItem] = dataSource.value.splice(oldIndex, 1); dataSource.value.splice(newIndex, 0, movedItem); dataSource.value = [...dataSource.value]; }, });
|