Home > Web Front-end > JS Tutorial > body text

The interceptor determines the operation after the token fails and jumps.

php中世界最好的语言
Release: 2018-04-16 14:02:05
Original
3192 people have browsed it

This time I will bring you the operation after the interceptor determines the token invalid jump. What are the precautions after the interceptor determines the token invalid jump. The following is a practical case, let's take a look.

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
  })
})
Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Detailed explanation of the steps for setting header information in the vue-resource interceptor

js css perfect web page loading User experience at the time

The above is the detailed content of The interceptor determines the operation after the token fails and jumps.. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!