feat:Drag&&drop_sorting

This commit is contained in:
dichgrem
2025-11-28 11:07:19 +08:00
parent c9b8ac0a66
commit 4d887e2aab
4 changed files with 32 additions and 5 deletions

View File

@@ -1,7 +1,15 @@
<template>
<div class="tdContainer">
<ul class="tdList">
<li class="tdItem" v-for="item in todos" :key="item.id">
<li
class="tdItem"
v-for="(item, index) in todos"
:key="item.id"
draggable="true"
@dragstart="onDragStart(index)"
@dragover.prevent="onDragOver(index)"
@drop="onDrop(index)"
>
<div class="tdItem-main">
<input type="checkbox" v-model="item.completed" class="toToggle" />
@@ -101,7 +109,15 @@ export default {
delTodo(item) {
this.$emit("delTodo", item);
},
onDragStart(index) {
this.dragIndex = index;
},
onDragOver(index) {},
onDrop(index) {
if (this.dragIndex === null || this.dragIndex === index) return;
this.$emit("move", { oldIndex: this.dragIndex, newIndex: index });
this.dragIndex = null;
},
},
};
</script>