axios拦截器

作用:在网络请求的时候在发起请求或者响应时对操作进行响应的处理
两大类
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>

个人理解,拦截器挺像遮羞布的,虽然他可以实现操作后的动画效果,是很炫,但我怎么觉得这个是为了掩饰后端处理的时延而不得已为之。

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值