undefinedfix
Sign in

A token has been saved in localstorage. Why do you want to save it again in vuex

3r1k edited in Mon, 26 Sep 2022

Problem description

The background of the problem and what methods have you tried

Related codes

//Please paste the code text below (do not use pictures instead of codes)

What are your expectations? What is the actual error message?

6 Replies
veritas1
commented on Tue, 27 Sep 2022

It is mainly used for data monitoring and rendering layer. For example, when the token disappears, it will automatically jump to the login page, and when the token is saved, it will automatically jump to the home page. If you operate localstorage directly, you need to monitor events yourself

ydczr
commented on Tue, 27 Sep 2022

Specifically, it should be combined with your business scenario. Theoretically, if you save it in localstorage, you don't need to save it in vuex.

dianna2009
commented on Tue, 27 Sep 2022

The token is stored in vuex, and the page will not be refreshed.

amrobx
commented on Tue, 27 Sep 2022

Generally, vuex is used. Localstorage can be used after refresh, and the vuex refresh will be gone. Initialize the variables stored in localstorage to prevent refresh.

darkmoonman
commented on Tue, 27 Sep 2022

I think vuex is stored in memory, and the characteristic of memory is fast. Every time you send a request to the back end to read the token, it will be a little faster... I understand

jjsig
commented on Wed, 28 Sep 2022

In fact, all localstorage should be stored in vuex, because the reading of localstorage is a disk reading, and the reading speed is far lower than that of vuex's memory reading. In order to avoid repeated reading of localstorage and affecting the performance, we need to put the data of localstorage into vuex for maintenance. See this article

lock This question has been locked and the reply function has been disabled.