Can axios configure public params?

if the question belongs to
I have three fields that must be added to all requests and must be placed in params
now what I want to ask is does axios have a way to configure these three fields as common parameters
Thank you all for answering

first.
Mar.03,2021

const requestBefore = (config) = > {
config. Params = {

//

};
return config;
}

axios.interceptors.request.use (requestBefore);


just add it to the interceptor


you can take a look at "

  1. transformRequest add
axios.defaults.transformRequest = [function(data) {
    ...
}];

2. Add

to the interceptor

axios interceptor (you can also use this as a loading. before each request) attach a link link description

service.interceptors.request.use( 
  config => {
    // token token
    const USER_TOKEN = JSON.parse(sessionStorage.getItem('user')) && JSON.parse(sessionStorage.getItem('user')).USER_TOKEN
    // token,
    if(USER_TOKEN && !config.url.includes('login')){
      config.headers.common['USER_TOKEN'] = USER_TOKEN
    }
    return config
  },
  err => {
    return Promise.reject(err)
  }
)

what I answered before is more or less the same. You can take a look at

.
Menu