Add fruit to API

This commit is contained in:
2020-12-07 17:49:13 +01:00
parent 83c1269d25
commit 663569e9dd
6 changed files with 211 additions and 65 deletions

View File

@@ -15,6 +15,14 @@ export default {
getFruit: async ({ commit }, id) => {
await axios.get(`http://localhost:3000/fruit/${id}`).then(res => commit("setFruit", res.data));
},
addFruit: async ({ commit }, fruit) => {
commit("setLoading", true);
await axios
.post("http://localhost:3000/fruit", fruit)
.then(res => commit("addFruit", res.data))
.catch(err => console.log(err))
.finally(() => commit("setLoading", false));
},
removeFruit: async ({ commit }, id) => {
await axios
.delete(`http://localhost:3000/fruit/${id}`)