hilongjw / vue-progressbar

A lightweight progress bar for vue
http://hilongjw.github.io/vue-progressbar
MIT License
1.46k stars 162 forks source link

Progress bar for all api calls at one place in Vue Resource interceptors #75

Open srabanicn opened 6 years ago

srabanicn commented 6 years ago

How can I configure the progress bar for all api calls within Vue Resource Interceptors so that if any API is called it will automatically shows the progress bar on request made and finish/fail according to the response.

I'm using the below code for progress bar and interceptors.

import VueProgressBar from 'vue-progressbar' const options = { ... } Vue.use(VueProgressBar, options)

Vue.http.interceptors.push((request, next) => { next((response) => { /** some response content**/ }) })

NOTE: I am not interested to use axios. Solution should be on Vue Resource.

chiaweilee commented 5 years ago

yes, use interceptors.

this should be vm, maybe you can find vm in interceptors, try this:

window.vm = new Vue({...})
piyushSinghalDemo commented 5 years ago

@chiaweilee same I am also trying but not getting working in vue-resource intercepter can you please give one simple example. I am trying let vm = new Vue({}); Vue.http.interceptors.push((request, next) => { vm.$Progress.start(); // for every request start the progress }) It is same in main.js. still it is showing error that can not read start of undefined.