mutations.js 501 B

123456789101112131415161718192021222324252627282930
  1. export default {
  2. ADD_TODO (state, text) {
  3. state.todos.unshift({
  4. text: text,
  5. done: false
  6. })
  7. },
  8. DELETE_TODO (state, todo) {
  9. state.todos.$remove(todo)
  10. },
  11. TOGGLE_TODO (state, todo) {
  12. todo.done = !todo.done
  13. },
  14. EDIT_TODO (state, todo, text) {
  15. todo.text = text
  16. },
  17. TOGGLE_ALL (state, done) {
  18. state.todos.forEach((todo) => {
  19. todo.done = done
  20. })
  21. },
  22. CLEAR_COMPLETED (state) {
  23. state.todos = state.todos.filter(todo => !todo.done)
  24. }
  25. }