mirror of
https://github.com/Dichgrem/Vue.git
synced 2025-12-16 13:41:59 -05:00
Compare commits
2 Commits
6e902bcc13
...
c9b8ac0a66
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c9b8ac0a66 | ||
|
|
89c2adcc50 |
@@ -30,36 +30,44 @@ export default {
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
methods: {
|
||||
// 添加待办
|
||||
addTodo(newTodo) {
|
||||
this.todos.push({
|
||||
const todo = {
|
||||
id: Date.now(),
|
||||
txt: newTodo,
|
||||
completed: false,
|
||||
});
|
||||
};
|
||||
this.todos.push(todo);
|
||||
console.log("添加 Todo:", todo);
|
||||
},
|
||||
|
||||
// 删除待办
|
||||
delTodo(item) {
|
||||
console.log("删除 Todo:", item);
|
||||
this.todos = this.todos.filter((t) => t.id !== item.id);
|
||||
},
|
||||
|
||||
toggleTodo(item) {
|
||||
console.log("完成状态切换:", item);
|
||||
},
|
||||
|
||||
changeTabType(type) {
|
||||
console.log("切换 Tab:", type);
|
||||
this.tabType = type;
|
||||
},
|
||||
},
|
||||
|
||||
// 深度监听 — 自动写入 localStorage
|
||||
watch: {
|
||||
todos: {
|
||||
handler(todos) {
|
||||
console.log("Todos 改变:", todos);
|
||||
localStorage.setItem("vue-todos", JSON.stringify(todos));
|
||||
},
|
||||
deep: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -3,5 +3,6 @@ import vue from "@vitejs/plugin-vue";
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
base: './',
|
||||
plugins: [vue()],
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user