Skip to content

Commit

Permalink
feat: allow disable progress per request. closes #112.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pooya Parsa committed Mar 5, 2018
1 parent ab2717b commit 1530bb6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 6 additions & 0 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ If set to `true`, `http://` in both `baseURL` and `browserBaseURL` will be chang

Integrate with Nuxt.js progress bar to show a loading bar while making requests. (Only on browser, when loading bar is available.)

You can also disable progress bar per request using `progress` config.

```js
this.$axios.$get('URL', { progress: false })
```

### `proxy`

* Default: `false`
Expand Down
18 changes: 15 additions & 3 deletions lib/plugin.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,31 @@ const setupProgress = (axios, ctx) => {

let currentRequests = 0

axios.onRequest(() => {
axios.onRequest(config => {
if (config && config.progress === false) {
return
}

currentRequests++
})

axios.onResponse(() => {
axios.onResponse(response => {
if (response && response.config && response.config.progress === false) {
return
}

currentRequests--
if (currentRequests <= 0) {
currentRequests = 0
$loading().finish()
}
})

axios.onError(() => {
axios.onError(error => {
if (error && error.config && error.config.progress === false) {
return
}

currentRequests--
$loading().fail()
$loading().finish()
Expand Down

0 comments on commit 1530bb6

Please sign in to comment.