


Detailed explanation of Vue-resource interceptor's judgment of token invalid jump
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 }) })
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Solutions to invalid login token include checking whether the Token has expired, checking whether the Token is correct, checking whether the Token has been tampered with, checking whether the Token matches the user, clearing the cache or cookies, checking the network connection and server status, logging in again or requesting a new Token. Contact technical support or developers, etc. Detailed introduction: 1. Check whether the Token has expired. The login Token usually has a validity period set. Once the validity period exceeds, it will be considered invalid, etc.

The problem of invalid login token can be solved by checking the network connection, checking the token validity period, clearing cache and cookies, checking login status, contacting the application developer and strengthening account security. Detailed introduction: 1. Check the network connection, reconnect to the network or change the network environment; 2. Check the token validity period, obtain a new token, or contact the developer of the application; 3. Clear cache and cookies, clear browser cache and Cookie, and then log in to the application again; 4. Check the login status.

In Vue application development, using vue-resource to make HTTP requests is a common operation. Although vue-resource provides many convenient functions, sometimes we encounter error messages such as "Error: timeoutofxxxmsexceeded". This error is usually caused by a request timeout. So, in this case, how should we solve this problem? 1. Increase the request timeout. First, we can increase the request timeout by

Redis stores user tokens. When designing a system similar to e-commerce, a common requirement is that each page needs to carry logged-in user information. There are two common solutions: using cookies to save and using JWT to save. But if Redis cache is used in the system, there is also a third solution - caching the user token in Redis. Generate a token when logging in and store it in Redis //Generate a token object and save it in redis redisTemplate.opsForHash().put("token","user",user)

How to solve the common problem of Laravel login time expiration When using Laravel to develop web applications, login authentication is a very important function. However, sometimes if a user does not operate for a long time after logging in, the page may automatically log out or the authentication may fail. This problem is relatively common. The following will introduce how to solve this problem by setting the session time and provide specific code examples. 1. Set the session expiration time in Laravel, by default sessi

1. Token login authentication jwt: JSONWebToken. It is an authentication protocol that is generally used to verify the requested identity information and identity permissions. Composed of three parts: Header, Hayload, Signatureheader: that is, the header information, which is the basic information describing this token, json format {"alg":"HS256", //indicates the signature algorithm, the default is HMACSHA256 (written as HS256) "type":"JWT"//Indicates the type of Token. JWT tokens are uniformly written as JWT}pa

Vue.js is a popular front-end framework, and many people use Vue.js in their projects. In Vue.js development, we often use the vue-resource plug-in to perform asynchronous request operations. However, when we use vue-resource in a local environment, the error message "Notallowedtoloadlocalresource:file:///xxx" may appear in the console. Let’s introduce it in detail below

PHP and REDIS: How to implement distributed cache invalidation and update Introduction: In modern distributed systems, cache is a very important component, which can significantly improve the performance and scalability of the system. At the same time, cache invalidation and update is also a very important issue, because if the invalidation and update of cache data cannot be handled correctly, it will lead to system data inconsistency. This article will introduce how to use PHP and REDIS to implement distributed cache invalidation and update, and provide relevant code examples. 1. What is RED
