Refactor axios code into service.
This commit is contained in:
parent
4a3e5e2557
commit
1ace587458
|
@ -0,0 +1,16 @@
|
|||
import axios from 'axios'
|
||||
|
||||
const apiClient = axios.create({
|
||||
baseURL: 'http://localhost:3000',
|
||||
withCredentials: false,
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
})
|
||||
|
||||
export default {
|
||||
getNotes() {
|
||||
return apiClient.get('/notes')
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
import { createStore } from 'vuex'
|
||||
import axios from 'axios'
|
||||
import NoteService from '@/services/NoteService.js'
|
||||
|
||||
export default createStore({
|
||||
state() {
|
||||
|
@ -9,8 +9,7 @@ export default createStore({
|
|||
},
|
||||
mutations: {
|
||||
FETCH_NOTES(state) {
|
||||
axios
|
||||
.get('http://localhost:3000/notes')
|
||||
NoteService.getNotes()
|
||||
.then(response => {
|
||||
state.notes = response.data
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue