hilongjw / vue-progressbar

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

How to use global for all request in axios?? #90

Closed cuongdevjs closed 5 years ago

cuongdevjs commented 5 years ago

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??

malinbranduse commented 5 years ago

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?

cuongdevjs commented 5 years ago

Many Thanks. I has resolved