How do I send custom parameters to the axios interceptor? I am using an interceptor like this:
JavaScript
x
10
10
1
window.axios.interceptors.request.use(function (config) {
2
if (PASSED_PARAM == true) {
3
doSomethingAwesome();
4
}
5
6
return config;
7
}, function (error) {
8
return Promise.reject(error);
9
});
10
I also have a response interceptor that needs to receive the same parameter.
Advertisement
Answer
The method suggested by @Laurent will cause axios to wipe out all your other parameters and replace it with my_variable
, which is may not exactly what you want.
The proper way of adding default parameters instead of replacing it is like this:
JavaScript
1
8
1
axios.defaults.params = {};
2
axios.interceptors.request.use(function (config) {
3
config.params['blah-defaut-param'] = 'blah-blah-default-value';
4
return config;
5
}, function (error) {
6
return Promise.reject(error);
7
});
8
This works with axios 0.18.1
. It does not work with axios 0.19
due to a regression bug…, I believe it will be fixed soon.