作用:在網路請求的時候在發起請求或者回應時對操作進行回應的處理
兩大類
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>
個人理解,攔截器挺像遮羞布的,雖然他可以實作操作后的影片效果,是很炫,但我怎么覺得這個是為了掩飾后端處理的時延而不得已為之,
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/264854.html
標籤:其他
