hilongjw/vue-progressbar

How to use global for all request in axios??

cuongdevjs opened this issue · 2 comments

i have this code:

import axios from 'axios'
import app from '../main'


let instance = axios.create({
  baseURL: ''
})


instance.interceptors.request.use(config => {
  app.$Progress.start(); // for every request start the progress
  console.log(config)
  return config;
});

instance.interceptors.response.use(response => {
  app.$Progress.finish(); // finish when a response is received
  console.log(response)
  return response;
});

export default instance;

But i import it to main.js it not working? Should i do??

Hi @CuongStf !

Technically you shouldn't import this in the main.js file because it would be a cyclical dependecy, you import app from main in the axios file but you also import axios axios in the main file. Makes sense?
Can you provide the main.js as well?

Many Thanks. I has resolved