Compare commits

...

2 Commits

Author SHA1 Message Date
dichgrem
db48b95509 fix:toggleTodo 2025-12-01 13:28:47 +08:00
dichgrem
62e283907a update:readme 2025-12-01 12:55:42 +08:00
5 changed files with 52 additions and 4 deletions

View File

@@ -1,2 +1,32 @@
# Vue # Vue
This is a Vue test on school.
<p align="center">
<img src="https://github.com/Dichgrem/Vue/blob/main/todos/view.png" width="300">
</p>
## 概述
这是一个基于 **Vue 3 + Pinia** 的轻量级待办事项 (Todo) 项目,具有以下功能:
* 添加/删除/编辑待办事项
* 按照全部 / 未完成 / 已完成进行筛选
* 拖拽排序待办事项
* 一键清除已完成事项
* 本地存储 (`localStorage`) 数据持久化
* 控制台打印操作日志,便于调试
## 结构
```
.
├── App.vue # 根组件,管理整体状态和方法
├── main.js # 项目入口
├── stores/todo.js # Pinia 状态管理,存储 todos 数据和操作方法
├── components
│ ├── TodoHeader.vue # 输入框和添加功能
│ ├── TodoList.vue # 待办事项列表,支持编辑和拖拽排序
│ └── TodoFooter.vue # 底部统计、筛选和清除已完成
├── assets # 静态资源CSS/图片)
└── style.css # 全局样式
```

View File

@@ -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

View File

@@ -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,

View File

@@ -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();

BIN
todos/view.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB