(vue, react) use axios request interface state monitoring processing
Complete process
1. Introduce the axios object:
import axios from 'axios';
2. Set the request address:
axios.defaults.baseURL = 'http://XXX.com';
3. Request timeout setting:
axios.defaults.timeout = 180000; // 请求超时时间
4. Set the request header:
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
axios.defaults.headers.get['Content-Type'] = 'application/x-www-form-urlencoded';
5. Status monitoring and processing of the request interface (knock on the blackboard! Important! Important! Important!):
(1) Intercept processing before request:
Arrow function writing method (recommended)
axios.interceptors.request.use(
config => {
~这里是相应的处理逻辑~
return config