当前位置:网站首页>Maintain login and route jump
Maintain login and route jump
2022-07-27 05:39:00 【My name is Lili】
1: Refresh to keep him logged in 2: After logging in, he will not be allowed to log in 3: Close the browser and then open it without logging in again ,
.
Solution :
stay storageUtils Introduced inside store Define a key be called user_key The value is b0344_user_key
( And then this b0344_user_key Define a constant ) And then use set get remove I always use this one key Change it if you want b0344_user_key Just fine

In this way, if I log in successfully, I need to save
stay memoryUtils Save it , And then storageUtils Save it

Then the program entry main.js Look inside storageUtils Does it exist , If it exists, go to memoryUtils.user Save it , Used to judge whether the user has logged in , Prevent closing the browser and reopening memoryUtils Initialization becomes empty

Click login twice to enter the login page .
Because I trigger actions When it comes to methods ,, You can judge this condition directly with one click , Now user There is no information in it , dispath The asynchronous operation is performed , The second click dispatch Only after the asynchronous operation , So put this judgment on actions Only when you operate inside . Comment out the saving operation of the component .
And in dipach Method to be passed into the routing object , otherwise actions There is no routing object in it , Deconstruction assignment should also be deconstructed

Next, perform permission verification , See if you have logged in , I haven't logged you in , Log in and let you go to the login page .、
Could have been in main.js It's written inside, but it's extracted , So in main.js It is necessary to introduce import "./permiassion"
Use routing guard -router.beforEach
There are two parameters router.beforEach(to Where to? ,from Where did you come from ,next What to do next )=>
use : stay src Create under directory permission.js, Check here .
Before route jump , First get user Whether the object exists , And it is not an empty object

边栏推荐
- 维持登录,路由跳转
- JS中如何判断一个对象是空对象
- First knowledge of C language - why does every C program have a main function
- Initial C language -- the function of keyword static
- Asynchronous data SMS verification code
- Js中如何进行隐式转换
- Time complexity and space complexity
- First knowledge of C language -- constants and variables
- Qsort - the sorting function in C language (with void*, callback function knowledge points
- First acquaintance with C language - first acquaintance with pointer
猜你喜欢

Hi3516DV300环境搭建

C WPF uses listbox to implement ruler control

First knowledge of C language -- what is C language

p7 day1 初识Flask框架

Source code of document type full-text retrieval knowledge base management system

Dnsmasq Usage Summary

页面的配置

权限展示-左侧列表动态化

eval与assert执行一句话木马

First knowledge of C language -- common data types
随机推荐
Pytorch installation new pit
弹性盒/伸缩盒(flex)的使用
Time complexity and space complexity
迭代器和生成器
elment-ui使用方法
规格管理,及规格选项管理功能实现
分享力扣—189.轮转数组 的三种解法
JS中是如何使用for..of来遍历对象
Qsort - the sorting function in C language (with void*, callback function knowledge points
Hi3516dv300 environment setup
C语言初阶——分支语句(if,switch)
flask蓝图
Hi3516DV300环境搭建
Introduction to C language functions
Native token generation encryption and decryption
GalleryCMS下载安装与配置
C language string function: strlen, strcpy, strcat
JS中原型及原型链
C语言函数入门介绍
node 安装调试