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 { createStore } from 'vuex'
|
||||||
import axios from 'axios'
|
import NoteService from '@/services/NoteService.js'
|
||||||
|
|
||||||
export default createStore({
|
export default createStore({
|
||||||
state() {
|
state() {
|
||||||
|
@ -9,8 +9,7 @@ export default createStore({
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
FETCH_NOTES(state) {
|
FETCH_NOTES(state) {
|
||||||
axios
|
NoteService.getNotes()
|
||||||
.get('http://localhost:3000/notes')
|
|
||||||
.then(response => {
|
.then(response => {
|
||||||
state.notes = response.data
|
state.notes = response.data
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue