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

 

原网站

版权声明
本文为[My name is Lili]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/208/202207270502339665.html