作用:在网络请求的时候在发起请求或者响应时对操作进行响应的处理
两大类
request请求方向的
<body>
<script src="https:"unpkg.com/axios/dist/axios.min.js"></script>
<script>
Axios.interceptors.request.use(config=>{ //请求方向拦截器设置
Console.log("进入响应拦截器");
Console.log(config);
}).catch(err =>{
Console.log("请求拦截失败");
Console.log(err);
})
//设置请求
Axios.get("http://localhost:9999/student/student/getallstustudent").then(res =>P{
Console.log(res);
})
</scirpt>
</body>
response响应方向的
<body>
<script src="https:"unpkg.com/axios/dist/axios.min.js"></script>
<script>
Axios.interceptors.response.use(config=>{ //请求方向拦截器设置
Console.log("进入请求拦截器");
Console.log(config);
}).catch(err =>{
Console.log("响应拦截失败");
Console.log(err);
})
//设置请求
Axios.get("http://localhost:9999/student/student/getallstustudent").then(res =>P{
Console.log(res);
})
</scirpt>
</body>
个人理解,拦截器挺像遮羞布的,虽然他可以实现操作后的动画效果,是很炫,但我怎么觉得这个是为了掩饰后端处理的时延而不得已为之。