How to use global for all request in axios??
cuongdevjs opened this issue · 2 comments
cuongdevjs commented
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
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
Many Thanks. I has resolved