Todos接口重构——批量清空任务- axios.delete(‘todos/’ + item.id)
src/store/ActionCreator.js
export const clearAllActionAsync = () => {
return async (dispatch) => {
// 清除所有已完成任务
let list = await axios.get('todos')
list.data.forEach(item => {
if (item.done) {
// 如果已完成才清空
axios.delete('todos/' + item.id)
}
})
let action = clearAllAction()
dispatch(action)
}
}
清空前
清空后