Refactor axios code into service.
This commit is contained in:
		
							
								
								
									
										16
									
								
								src/services/NoteService.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/services/NoteService.js
									
									
									
									
									
										Normal 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') | ||||
|   } | ||||
| } | ||||
| @ -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 | ||||
|         }) | ||||
|  | ||||
		Reference in New Issue
	
	Block a user