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

Detailed explanation of Vue-resource interceptor's judgment of token invalid jump

小云云
Release: 2018-01-20 13:15:47
Original
2183 people have browsed it

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 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

Related recommendations:

How to jump to the login page after Ajax Session failure

vue implements the post-login page Jump to previous page example sharing

Detailed explanation of how PHP jumps to the corresponding web page according to the user language

The above is the detailed content of Detailed explanation of Vue-resource interceptor's judgment of token invalid jump. 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!