Skip to content

Commit 9b1827f

Browse files
committed
Bump: v0.1.5
compatible with Axios
1 parent 98d3bf9 commit 9b1827f

File tree

4 files changed

+69
-23
lines changed

4 files changed

+69
-23
lines changed

dist/vue-nprogress.js

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* nprogress v0.1.4
2+
* nprogress v0.1.5
33
* https://github.com/vue-bulma/nprogress
44
* Released under the MIT License.
55
*/
@@ -80,17 +80,37 @@ function install(Vue) {
8080
_this._nprogress = np;
8181
np.init(_this);
8282

83-
var http = applyOnHttp && Vue.http;
84-
if (http) {
85-
http.interceptors.push(function (request, next) {
86-
var showProgressBar = 'showProgressBar' in request ? request.showProgressBar : applyOnHttp;
87-
if (showProgressBar) initProgress();
83+
if (applyOnHttp) {
84+
var http = Vue.http;
85+
var axios = Vue.axios;
8886

89-
next(function (response) {
90-
if (!showProgressBar) return response;
91-
increase();
87+
if (http) {
88+
http.interceptors.push(function (request, next) {
89+
var showProgressBar = 'showProgressBar' in request ? request.showProgressBar : applyOnHttp;
90+
if (showProgressBar) initProgress();
91+
92+
next(function (response) {
93+
if (!showProgressBar) return response;
94+
increase();
95+
});
9296
});
93-
});
97+
} else if (axios) {
98+
axios.interceptors.request.use(function (request) {
99+
if (!('showProgressBar' in request)) request.showProgressBar = applyOnHttp;
100+
if (request.showProgressBar) initProgress();
101+
return request;
102+
}, function (error) {
103+
return Promise.reject(error);
104+
});
105+
106+
axios.interceptors.response.use(function (response) {
107+
if (response.config.showProgressBar) increase();
108+
return response;
109+
}, function (error) {
110+
if (error.config && error.config.showProgressBar) increase();
111+
return Promise.reject(error);
112+
});
113+
}
94114
}
95115

96116
var router = applyOnRouter && _this.$options.router;
@@ -124,6 +144,8 @@ function NProgress(options) {
124144

125145
NProgress.install = install;
126146

147+
NProgress.start = function () {};
148+
127149
Object.assign(NProgress.prototype, nprogress, {
128150
init: function (app) {
129151
this.app = app;

dist/vue-nprogress.min.js

Lines changed: 2 additions & 2 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-nprogress",
3-
"version": "0.1.4",
3+
"version": "0.1.5",
44
"description": "Slim progress bars is based on nprogress for Ajax'y applications",
55
"repository": "vue-bulma/nprogress",
66
"scripts": {

src/index.js

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,37 @@ function install(Vue, options = {}) {
5858
this._nprogress = np
5959
np.init(this)
6060

61-
const http = applyOnHttp && Vue.http
62-
if (http) {
63-
http.interceptors.push((request, next) => {
64-
const showProgressBar = 'showProgressBar' in request ? request.showProgressBar : applyOnHttp
65-
if (showProgressBar) initProgress()
66-
67-
next(response => {
68-
if (!showProgressBar) return response
69-
increase()
61+
if (applyOnHttp) {
62+
const http = Vue.http
63+
const axios = Vue.axios
64+
65+
if (http) {
66+
http.interceptors.push((request, next) => {
67+
const showProgressBar = 'showProgressBar' in request ? request.showProgressBar : applyOnHttp
68+
if (showProgressBar) initProgress()
69+
70+
next(response => {
71+
if (!showProgressBar) return response
72+
increase()
73+
})
7074
})
71-
})
75+
} else if (axios) {
76+
axios.interceptors.request.use((request) => {
77+
if (!('showProgressBar' in request)) request.showProgressBar = applyOnHttp
78+
if (request.showProgressBar) initProgress()
79+
return request
80+
}, (error) => {
81+
return Promise.reject(error)
82+
})
83+
84+
axios.interceptors.response.use((response) => {
85+
if (response.config.showProgressBar) increase()
86+
return response
87+
}, (error) => {
88+
if (error.config && error.config.showProgressBar) increase()
89+
return Promise.reject(error)
90+
})
91+
}
7292
}
7393

7494
const router = applyOnRouter && this.$options.router
@@ -101,6 +121,10 @@ function NProgress(options) {
101121

102122
NProgress.install = install
103123

124+
NProgress.start = function () {
125+
126+
}
127+
104128
Object.assign(NProgress.prototype, nprogress, {
105129
init (app) {
106130
this.app = app

0 commit comments

Comments
 (0)