Implement actually adding notes to the db.
This commit is contained in:
parent
1ace587458
commit
a4cf194672
|
@ -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 = ''
|
||||
}
|
||||
},
|
||||
|
|
|
@ -12,5 +12,8 @@ const apiClient = axios.create({
|
|||
export default {
|
||||
getNotes() {
|
||||
return apiClient.get('/notes')
|
||||
},
|
||||
addNote(text) {
|
||||
return apiClient.post('/notes', JSON.stringify({ text }))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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: {}
|
||||
|
|
Loading…
Reference in New Issue