commit | author | age
|
82de6c
|
1 |
import axios from "axios"; |
D |
2 |
import config from "@/config"; |
|
3 |
|
|
4 |
export default { |
|
5 |
loadTodos({ commit }) { |
|
6 |
axios |
|
7 |
.get(config.todoEndpoint) |
|
8 |
.then(r => r.data) |
|
9 |
.then(todos => { |
|
10 |
commit("SET_TODOS", todos); |
|
11 |
commit("SET_LOADING", false); |
|
12 |
}); |
|
13 |
}, |
|
14 |
addTodo({ commit, state }) { |
|
15 |
if (!state.newTodo) { |
|
16 |
// do not add empty todos |
|
17 |
return; |
|
18 |
} |
|
19 |
const todo = { |
|
20 |
title: state.newTodo, |
|
21 |
completed: false |
|
22 |
}; |
|
23 |
axios.post(config.todoEndpoint, todo).then(mongoTodo => { |
|
24 |
commit("ADD_TODO", mongoTodo); |
|
25 |
}); |
|
26 |
}, |
530b0a
|
27 |
setNewTodo ({ commit }, todo) { |
D |
28 |
commit('SET_NEW_TODO', todo) |
|
29 |
}, |
82de6c
|
30 |
clearNewTodo({ commit }) { |
D |
31 |
commit("CLEAR_NEW_TODO"); |
|
32 |
} |
|
33 |
}; |