23 Star 3 Fork 0

bingly/web2_2022

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
App.vue 2.78 KB
一键复制 编辑 原始数据 按行查看 历史
郭正怡 提交于 2022-04-20 03:43 . 哈哈哈
<template>
<div id="root">
<div class="todo-container">
<div class="todo-wrap">
<MyHeader @addTodo="addTodo" />
<MyList :todos="todos" />
<MyFooter
:todos="todos"
:checkAllTodo="checkAllTodo"
:clearAllTodo="clearAllTodo"
/>
</div>
</div>
</div>
</template>
<script>
import pubsub from 'pubsub-js'
import MyHeader from "./components/MyHeader.vue";
import MyFooter from "./components/MyFooter.vue";
import MyList from "./components/MyList.vue";
export default {
name: "App",
components: {
MyHeader,
MyFooter,
MyList,
},
data() {
return {
todos: JSON.parse(localStorage.getItem("todos")) || [],
};
},
methods: {
// 添加TODO
addTodo(todoObj) {
this.todos.unshift(todoObj);
},
// 勾选or取消勾选一个TODO
checkTodo(id) {
this.todos.forEach((todo) => {
if (todo.id === id) todo.done = !todo.done;
});
},
//更行todo
updateTodo(id,title) {
this.todos.forEach((todo) => {
if (todo.id === id) todo.title=title;
});
},
// 删除一个TODO
deleteTodo(_,id) {
this.todos = this.todos.filter((todo) => {
return todo.id !== id;
});
},
// 全选or取消全选
checkAllTodo(done) {
this.todos.forEach((todo) => {
todo.done = done;
});
},
// 清除所有已经完成的TODO
clearAllTodo() {
this.todos = this.todos.filter((todo) => {
return !todo.done;
});
},
},
watch: {
todos: {
deep: true,
handler(value) {
localStorage.setItem("todos", JSON.stringify(value));
},
},
},
mounted() {
this.$bus.$on("checkTodo", this.checkTodo);
this.$bus.$on('updateTodo',this.updateTodo)
this.pubId=pubsub.subscribe('deleteTodo',this.deleteTodo)
},
beforeDestroy() {
this.$bus.$off("checkTodo");
this.$bus.$off('updateTodo')
pubsub.unsubscribe(this.pubId)
},
};
</script>
<style>
/*base*/
body {
background: #fff;
}
.btn {
display: inline-block;
padding: 4px 12px;
margin-bottom: 0;
font-size: 14px;
line-height: 20px;
text-align: center;
vertical-align: middle;
cursor: pointer;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2),
0 1px 2px rgba(0, 0, 0, 0.05);
border-radius: 4px;
}
.btn-danger {
color: #fff;
background-color: #da4f49;
border: 1px solid #bd362f;
}
.btn-edit{
color: #fff;
background-color: rgb(31, 92, 117);
border: 1px solid rgb(169, 216, 234);
margin-right:5px;
}
.btn-danger:hover {
color: #fff;
background-color: #bd362f;
}
.btn:focus {
outline: none;
}
.todo-container {
width: 600px;
margin: 0 auto;
}
.todo-container .todo-wrap {
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
}
</style>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/bingly/web2_2022.git
git@gitee.com:bingly/web2_2022.git
bingly
web2_2022
web2_2022
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385