You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.7 KiB
74 lines
1.7 KiB
<template> |
|
<div class="todo-bottom" v-show="total"> |
|
<label> |
|
<input type="checkbox" v-model="isAll"> |
|
</label> |
|
<span> |
|
<span>已完成{{ totalDone }}</span>/全部{{ total }} |
|
</span> |
|
<button class="btn btn-danger" @click="clearAll">清除已完成任务</button> |
|
</div> |
|
</template> |
|
|
|
<script> |
|
export default { |
|
name: "TodoBottom", |
|
props: ['todos', 'checkAllTodo', 'clearAllTodo'], |
|
computed: { |
|
// 用于计算全部todo任务的总数量,并且通过v-show绑定到模板,用于控制模板的展示 |
|
total() { |
|
return this.todos.length |
|
}, |
|
// 用于统计全部已完成的todo任务数量 |
|
totalDone() { |
|
return this.todos.reduce((pre, todo) => pre + (todo.done ? 1 : 0), 0) |
|
}, |
|
// 计算方法的完整写法 |
|
// get方法用于判断是否全部任务被勾选, 返回布尔值 |
|
// set方法是封装了App中checkAllTodo方法用于勾选和取消勾选全部任务 |
|
isAll: { |
|
get() { |
|
return this.totalDone === this.total && this.total > 0 |
|
}, |
|
set(value) { |
|
this.checkAllTodo(value) |
|
} |
|
} |
|
}, |
|
methods: { |
|
// 封装App中的clearAllTodo方法,用于清除全部已完成数据 |
|
clearAll() { |
|
if (confirm("确认清除全部已完成任务?")) { |
|
this.clearAllTodo() |
|
} |
|
} |
|
} |
|
} |
|
</script> |
|
|
|
<style scoped> |
|
.todo-bottom { |
|
height: 40px; |
|
line-height: 40px; |
|
padding-left: 6px; |
|
margin-top: 5px; |
|
} |
|
|
|
.todo-bottom label { |
|
display: inline-block; |
|
margin-right: 20px; |
|
cursor: pointer; |
|
} |
|
|
|
.todo-bottom label input { |
|
position: relative; |
|
top: -1px; |
|
vertical-align: middle; |
|
margin-right: 5px; |
|
} |
|
|
|
.todo-bottom button { |
|
float: right; |
|
margin-top: 5px; |
|
} |
|
</style> |