Implement actually adding notes to the db.

This commit is contained in:
Lukáš Kucharczyk 2020-09-09 18:15:54 +02:00
parent 1ace587458
commit a4cf194672
3 changed files with 11 additions and 5 deletions

View File

@ -30,10 +30,7 @@ export default {
},
methods: {
addNote() {
this.$store.commit('ADD_NOTE', {
id: this.notes.length,
text: this.content
})
this.$store.commit('ADD_NOTE', this.content)
this.content = ''
}
},

View File

@ -12,5 +12,8 @@ const apiClient = axios.create({
export default {
getNotes() {
return apiClient.get('/notes')
},
addNote(text) {
return apiClient.post('/notes', JSON.stringify({ text }))
}
}

View File

@ -18,7 +18,13 @@ export default createStore({
})
},
ADD_NOTE(state, note) {
state.notes.push(note)
NoteService.addNote(note)
.then(() => {
this.commit('FETCH_NOTES')
})
.catch(error => {
console.error(error)
})
}
},
actions: {}