diff --git a/src/components/NoteList.vue b/src/components/NoteList.vue index c3f654b..4f54ecc 100644 --- a/src/components/NoteList.vue +++ b/src/components/NoteList.vue @@ -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 = '' } }, diff --git a/src/services/NoteService.js b/src/services/NoteService.js index 94cd171..cfc81c8 100644 --- a/src/services/NoteService.js +++ b/src/services/NoteService.js @@ -12,5 +12,8 @@ const apiClient = axios.create({ export default { getNotes() { return apiClient.get('/notes') + }, + addNote(text) { + return apiClient.post('/notes', JSON.stringify({ text })) } } diff --git a/src/store/index.js b/src/store/index.js index 08476b3..7cb81ad 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -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: {}