任务列表过滤——清空已完成任务-深拷贝-JSON.parse(JSON.stringify(obj)) & filter()-过滤数组
- 清空已完成任务
src/views/Footer.js
clearAll: () => {
// 清除已完成任务
let action = Actions.clearAllAction()
console.log(action)
dispatch(action)
}
在src/store/ActionCreator.js中
/*
ActionCreator 本质上是函数,用于创建Action
Action的本质是一个普通对象
*/
export const clearAllAction = () => {
return {
type: 'todos_clear_all'
}
}
- 数据变更
src/store/Reducer.js
case 'todos_clear_all':
// 清除已完成任务
newState = JSON.parse(JSON.stringify(state))
// 过滤出生于的未完成的任务
newState.todos = newState.todos.filter(item => {
return !item.done
})
return newState
清空效果