26 lines
551 B
JavaScript

import { createStore } from 'vuex'
import NoteService from '@/services/NoteService.js'
export default createStore({
state() {
return {
notes: [{ id: 1, text: 'A note from the Vuex store!' }]
}
},
mutations: {
FETCH_NOTES(state) {
NoteService.getNotes()
.then(response => {
state.notes = response.data
})
.catch(error => {
console.log('There was an error:', error.response)
})
},
ADD_NOTE(state, note) {
state.notes.push(note)
}
},
actions: {}
})