Refactor axios code into service.

This commit is contained in:
Lukáš Kucharczyk 2020-09-08 19:08:45 +02:00
parent 4a3e5e2557
commit 1ace587458
2 changed files with 18 additions and 3 deletions

View File

@ -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')
}
}

View File

@ -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
})