1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
const sort = async (newIndex: number, oldIndex: number) => {
if (newIndex === oldIndex) return;
const newData = [...tableData.value.rows];
const [movedItem] = newData.splice(oldIndex, 1);
newData.splice(newIndex, 0, movedItem);
newData.forEach((item, index) => {
item.index = index;
});
// Vue3 响应式更新方式
tableData.value = {
...tableData.value,
rows: [...newData] // 强制替换整个数组触发更新
};
sortData.value.tag_groups = newData.map(item => ({
tag_group_id: item.tag_group_id,
index: item.index
}));
isData .value += 1; // 每次拖拽后更新 key
}
|