Home > Article > Web Front-end > Vue-resource interceptor judges token failure and jumps
This article mainly brings you an example of Vue-resource interceptor judging token failure jump. The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor to take a look, I hope it can help everyone.
Set global token judgment in the interceptor, which means that the token will be verified for every http request, and the token expiration return code agreed with the background can customize the jump path;
var token = window.localStorage.getItem("token"); Vue.http.interceptors.push(function(request, next) { request.headers.set('token', token); //setting request.headers next(function(response){ if(response.body.code===401){ //与后台约定登录失效的返回码 parent.location.href ='/login.html'; } return response }) })
Related recommendations:
vue-resource interceptor setting header detailed explanation
Vue2.0 axios front and rear ends Login interceptor
Vue interceptor vue-resource Interceptor usage detailed explanation
The above is the detailed content of Vue-resource interceptor judges token failure and jumps. For more information, please follow other related articles on the PHP Chinese website!