mirror of
https://github.com/Dichgrem/Vue.git
synced 2025-12-16 05:31:59 -05:00
fix:toggleTodo
This commit is contained in:
@@ -28,6 +28,10 @@ function editTodo({ item, text }) {
|
|||||||
todoStore.editTodo({ item, text });
|
todoStore.editTodo({ item, text });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toggleTodo(item) {
|
||||||
|
todoStore.toggle(item);
|
||||||
|
}
|
||||||
|
|
||||||
function changeTabType(type) {
|
function changeTabType(type) {
|
||||||
console.log("App.vue tab change:", type);
|
console.log("App.vue tab change:", type);
|
||||||
todoStore.setTab(type);
|
todoStore.setTab(type);
|
||||||
@@ -50,6 +54,7 @@ const showTodos = computed(() => {
|
|||||||
@delTodo="delTodo"
|
@delTodo="delTodo"
|
||||||
@move="moveTodo"
|
@move="moveTodo"
|
||||||
@edit="editTodo"
|
@edit="editTodo"
|
||||||
|
:toggleTodo="toggleTodo"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TodoFooter
|
<TodoFooter
|
||||||
|
|||||||
@@ -11,8 +11,12 @@
|
|||||||
@drop="onDrop(index)"
|
@drop="onDrop(index)"
|
||||||
>
|
>
|
||||||
<div class="tdItem-main">
|
<div class="tdItem-main">
|
||||||
<input type="checkbox" v-model="item.completed" class="toToggle" />
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
:checked="item.completed"
|
||||||
|
@change="toggleTodo(item)"
|
||||||
|
class="toToggle"
|
||||||
|
/>
|
||||||
<!-- <span class="tdTxt" :class="{ completed: item.completed }"> -->
|
<!-- <span class="tdTxt" :class="{ completed: item.completed }"> -->
|
||||||
<!-- {{ item.txt }} -->
|
<!-- {{ item.txt }} -->
|
||||||
<!-- </span> -->
|
<!-- </span> -->
|
||||||
@@ -46,7 +50,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
props: ["todos"],
|
props: ["todos", "toggleTodo", "delTodo", "editTodo", "moveTodo"],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
editingId: null,
|
editingId: null,
|
||||||
|
|||||||
@@ -65,6 +65,15 @@ export const useTodoStore = defineStore("todoStore", {
|
|||||||
console.log("Current todos:", toRaw(this.todos));
|
console.log("Current todos:", toRaw(this.todos));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
toggle(item) {
|
||||||
|
const t = this.todos.find(t => t.id === item.id);
|
||||||
|
if (t) {
|
||||||
|
t.completed = !t.completed;
|
||||||
|
this.save();
|
||||||
|
console.log("Toggled:", t);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
clearCompleted() {
|
clearCompleted() {
|
||||||
this.todos = this.todos.filter((t) => !t.completed);
|
this.todos = this.todos.filter((t) => !t.completed);
|
||||||
this.save();
|
this.save();
|
||||||
|
|||||||
Reference in New Issue
Block a user