https://github.com/axios/axios
Interceptors
GitHub - axios/axios: Promise based HTTP client for the browser and node.js
axios.interceptors.request
//サーバに送信する前にhttpheaderなどの情報を変える時に使用する。トークンをつけたり
axios.interceptors.response
//レスポンスを受け取った後にthenやcatchにデータを渡す前のデータを確認することができる。エラーモーダルを出したい時
この機能を使いたくない時は
const myInterceptor = axios.interceptors.request.use(function () {/*...*/});
🔼これで自動で連番を作成する。複数*interceptorsを作ってある一つのみ動かしたくない時に使用する。
ファイルを分割して使用する時にinterceptorsを使用する時に使用する*
axios.interceptors.request.eject(myInterceptor);
axios.defaults
axios.defaults.baseURL = '<https://api.example.com>';
// Important: If axios is used with multiple domains, the AUTH_TOKEN will be sent to all of them.
// See below for an example using Custom instance defaults instead.
axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
axios.create()
GitHub - axios/axios: Promise based HTTP client for the browser and node.js