Skip to content

Commit 73ef02e

Browse files
committed
Progress bar with axios interceptors
1 parent b856043 commit 73ef02e

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"dependencies": {
1111
"axios": "^0.18.0",
1212
"lodash": "^4.17.11",
13+
"nprogress": "^0.2.0",
1314
"vue": "^2.5.17",
1415
"vue-router": "^3.0.1",
1516
"vuejs-datepicker": "^1.5.3",

src/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import App from './App.vue'
55
import router from './router'
66
import store from './store/store'
77
import BaseIcon from '@/components/BaseIcon'
8+
import 'nprogress/nprogress.css'
89

910
Vue.component('BaseIcon', BaseIcon)
1011

src/services/EventService.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import axios from 'axios'
2+
import NProgress from 'nprogress'
23

34
const apiClient = axios.create({
45
baseURL: `http://localhost:3000`,
@@ -9,6 +10,16 @@ const apiClient = axios.create({
910
}
1011
})
1112

13+
apiClient.interceptors.request.use(config => {
14+
NProgress.start()
15+
return config
16+
})
17+
18+
apiClient.interceptors.response.use(response => {
19+
NProgress.done()
20+
return response
21+
})
22+
1223
export default {
1324
getEvents(perPage, page) {
1425
return apiClient.get('/events?_limit=' + perPage + '&_page=' + page)

0 commit comments

Comments
 (0)