当前位置:网站首页>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

边栏推荐
猜你喜欢
随机推荐
使用vertical-align不能让图片和文字垂直居中对齐
c语言字符串函数下:strcmp、strncpy、strncat、strncmp、strstr、strtok、strerror
用户页面管理
eval与assert执行一句话木马
JS如何判断一个对象是否属于一个类
C语言中堆内存介绍和管理
Dnsmasq Usage Summary
Project login and registration ideas
MySQL cancels the foreign key Association constraint
qsort — c语言中自带的排序函数(附带void*、回调函数知识点
Redis transaction
node 安装调试
flask项目配置
初识C语言——常见的数据类型
C language string function: StrCmp, strncpy, strncat, strncmp, strstr, strtok, strError
C语言指针入门详细介绍
JS中数组的遍历方法有哪些
JS中是如何使用for..of来遍历对象
C语言入门介绍
元素显示模式:块级,行内,行内块,嵌套规范,显示模式转换









