How does vue store user information, such as user name, ID, etc.?

for a website, the user information (username, id, etc.) obtained from the background successfully logged in by the user wants to be displayed in the components of header, so how will vue save the user information?

1. This is not a complex system. I don"t think it is necessary to use vuex, to save user information, and after vuex refresh, the information is gone.
2. If you use localStorage or sessionStorage, users cannot use private browsing.
3, and the header component is registered after the login component, so you can"t use eventbus either.

I don"t know if you have any way to store user information, ask to share ~

Mar.23,2021

localStorage encryption, try this


self-answer: at present, you still use sessionStorage to store user token, global variables to store other user information. After refreshing data is lost, use token request.
2018-0-19, update answer : after the currently used policy user has successfully logged in, the token, returned by the backend is stored in storage. Then, the frontend uses this token to request user information from the backend and store this information (roles, permissions) in the vuex, so as to prevent the loss of information caused by user refresh. After the user refreshes the page, use this token to request user information from the backend again.


it can be determined that the session value is set by the backend after login. If the frontend gets


cookie?


cookie, I don't like it very much. Cookie carries it every time of the request, resulting in the request header is too large.
the latest API browser will have a database, HTML5 local database.
generally, after logging in, the information obtained from the server can be saved using vuex. If the vuex is too large, you can instantiate a data class and save the data through prototype, but there will be no refresh data.


the 1 and 3 you provide are definitely not good.
can only consider 2.

Privacy browsing method, which is due to the browser itself, cannot be solved because it does not want to save user information.
Menu