diff --git a/dist/vue-nprogress.js b/dist/vue-nprogress.js index 1eb9ba7..f1e284f 100644 --- a/dist/vue-nprogress.js +++ b/dist/vue-nprogress.js @@ -1,5 +1,5 @@ /*! - * nprogress v0.1.4 + * nprogress v0.1.5 * https://github.com/vue-bulma/nprogress * Released under the MIT License. */ @@ -80,17 +80,37 @@ function install(Vue) { _this._nprogress = np; np.init(_this); - var http = applyOnHttp && Vue.http; - if (http) { - http.interceptors.push(function (request, next) { - var showProgressBar = 'showProgressBar' in request ? request.showProgressBar : applyOnHttp; - if (showProgressBar) initProgress(); + if (applyOnHttp) { + var http = Vue.http; + var axios = Vue.axios; - next(function (response) { - if (!showProgressBar) return response; - increase(); + if (http) { + http.interceptors.push(function (request, next) { + var showProgressBar = 'showProgressBar' in request ? request.showProgressBar : applyOnHttp; + if (showProgressBar) initProgress(); + + next(function (response) { + if (!showProgressBar) return response; + increase(); + }); }); - }); + } else if (axios) { + axios.interceptors.request.use(function (request) { + if (!('showProgressBar' in request)) request.showProgressBar = applyOnHttp; + if (request.showProgressBar) initProgress(); + return request; + }, function (error) { + return Promise.reject(error); + }); + + axios.interceptors.response.use(function (response) { + if (response.config.showProgressBar) increase(); + return response; + }, function (error) { + if (error.config && error.config.showProgressBar) increase(); + return Promise.reject(error); + }); + } } var router = applyOnRouter && _this.$options.router; @@ -124,6 +144,8 @@ function NProgress(options) { NProgress.install = install; +NProgress.start = function () {}; + Object.assign(NProgress.prototype, nprogress, { init: function (app) { this.app = app; diff --git a/dist/vue-nprogress.min.js b/dist/vue-nprogress.min.js index 8d53725..d4d7dc6 100644 --- a/dist/vue-nprogress.min.js +++ b/dist/vue-nprogress.min.js @@ -1,7 +1,7 @@ /*! - * nprogress v0.1.4 + * nprogress v0.1.5 * https://github.com/vue-bulma/nprogress * Released under the MIT License. */ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("nprogress")):"function"==typeof define&&define.amd?define(["nprogress"],e):t.vueNprogress=e(t.nprogress)}(this,function(t){"use strict";function e(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.installed||(this.installed=!0,Object.defineProperty(t.prototype,"$nprogress",{get:function(){return this.$root._nprogress}}),e=Object.assign({},n,e),t.mixin({beforeCreate:function(){var r=this,n=this.$options.nprogress;n&&!function(){var o=function(){u=0,a=0,n.done()},s=function(){0===u&&setTimeout(function(){return n.start()},c),u++,n.set(a/u)},i=function(){setTimeout(function(){++a,a>=u?o():n.set(a/u-.1)},c+50)},u=0,a=0,f=e,c=f.latencyThreshold,p=f.router,h=f.http,g=!0;r._nprogress=n,n.init(r);var d=h&&t.http;d&&d.interceptors.push(function(t,e){var r="showProgressBar"in t?t.showProgressBar:h;r&&s(),e(function(t){return r?void i():t})});var l=p&&r.$options.router;l&&(l.beforeEach(function(t,e,r){var n="showProgressBar"in t.meta?t.meta.showProgressBar:p;n&&g&&(s(),g=!1),r()}),l.afterEach(function(t){var e="showProgressBar"in t.meta?t.meta.showProgressBar:p;e&&(i(),g=!0)}))}()}}))}function r(t){this.app=null,this.configure(t||{})}t="default"in t?t.default:t;var n={latencyThreshold:100,router:!0,http:!0};return r.install=e,Object.assign(r.prototype,t,{init:function(t){this.app=t}}),r}); \ No newline at end of file +!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("nprogress")):"function"==typeof define&&define.amd?define(["nprogress"],e):r.vueNprogress=e(r.nprogress)}(this,function(r){"use strict";function e(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.installed||(this.installed=!0,Object.defineProperty(r.prototype,"$nprogress",{get:function(){return this.$root._nprogress}}),e=Object.assign({},n,e),r.mixin({beforeCreate:function(){var t=this,n=this.$options.nprogress;n&&!function(){var o=function(){u=0,a=0,n.done()},s=function(){0===u&&setTimeout(function(){return n.start()},f),u++,n.set(a/u)},i=function(){setTimeout(function(){++a,a>=u?o():n.set(a/u-.1)},f+50)},u=0,a=0,c=e,f=c.latencyThreshold,p=c.router,h=c.http,g=!0;if(t._nprogress=n,n.init(t),h){var d=r.http,l=r.axios;d?d.interceptors.push(function(r,e){var t="showProgressBar"in r?r.showProgressBar:h;t&&s(),e(function(r){return t?void i():r})}):l&&(l.interceptors.request.use(function(r){return"showProgressBar"in r||(r.showProgressBar=h),r.showProgressBar&&s(),r},function(r){return Promise.reject(r)}),l.interceptors.response.use(function(r){return r.config.showProgressBar&&i(),r},function(r){return r.config&&r.config.showProgressBar&&i(),Promise.reject(r)}))}var P=p&&t.$options.router;P&&(P.beforeEach(function(r,e,t){var n="showProgressBar"in r.meta?r.meta.showProgressBar:p;n&&g&&(s(),g=!1),t()}),P.afterEach(function(r){var e="showProgressBar"in r.meta?r.meta.showProgressBar:p;e&&(i(),g=!0)}))}()}}))}function t(r){this.app=null,this.configure(r||{})}r="default"in r?r.default:r;var n={latencyThreshold:100,router:!0,http:!0};return t.install=e,t.start=function(){},Object.assign(t.prototype,r,{init:function(r){this.app=r}}),t}); \ No newline at end of file diff --git a/package.json b/package.json index db6b20f..a884d68 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-nprogress", - "version": "0.1.4", + "version": "0.1.5", "description": "Slim progress bars is based on nprogress for Ajax'y applications", "repository": "vue-bulma/nprogress", "scripts": { diff --git a/src/index.js b/src/index.js index 8c2717f..a2d6373 100644 --- a/src/index.js +++ b/src/index.js @@ -58,17 +58,37 @@ function install(Vue, options = {}) { this._nprogress = np np.init(this) - const http = applyOnHttp && Vue.http - if (http) { - http.interceptors.push((request, next) => { - const showProgressBar = 'showProgressBar' in request ? request.showProgressBar : applyOnHttp - if (showProgressBar) initProgress() - - next(response => { - if (!showProgressBar) return response - increase() + if (applyOnHttp) { + const http = Vue.http + const axios = Vue.axios + + if (http) { + http.interceptors.push((request, next) => { + const showProgressBar = 'showProgressBar' in request ? request.showProgressBar : applyOnHttp + if (showProgressBar) initProgress() + + next(response => { + if (!showProgressBar) return response + increase() + }) }) - }) + } else if (axios) { + axios.interceptors.request.use((request) => { + if (!('showProgressBar' in request)) request.showProgressBar = applyOnHttp + if (request.showProgressBar) initProgress() + return request + }, (error) => { + return Promise.reject(error) + }) + + axios.interceptors.response.use((response) => { + if (response.config.showProgressBar) increase() + return response + }, (error) => { + if (error.config && error.config.showProgressBar) increase() + return Promise.reject(error) + }) + } } const router = applyOnRouter && this.$options.router @@ -101,6 +121,10 @@ function NProgress(options) { NProgress.install = install +NProgress.start = function () { + +} + Object.assign(NProgress.prototype, nprogress, { init (app) { this.app = app