current position:Home>Where is the user information obtained by the front end

Where is the user information obtained by the front end

2022-04-29 05:16:15segmentfault

image.png
For example, this position , There is a user name , Age , Three user information , How to store appropriate ?
vuex+localstorage? There are other plans



Other answers 1:

The common front-end storage solutions I know :Cookie,LocalStorage and SessionStorage.
There are many schemes :https://www.cnblogs.com/minig....
Users' privacy information should be stored carefully , Delete in time .


Other answers 2:

Look at your project .
Larger ones vuex It may be easy to manage .
General use localStorage It will be more concise .


Other answers 3:

In the case of your screenshot, there is no need for additional storage .
After logging in, the front end should use sessionStorage Storage token( because localStorage It will not be automatically destroyed after the page is closed ), Then call... When needed api Just ask for data .
As far as your screenshot is concerned , This component completes itself api Once the data is requested and displayed, the task is over , No need to store data . The so-called storage is when the same data needs to be used in multiple components , Caching data for the purpose of avoiding frequent requests . So how to save it doesn't matter , Just get it .
What you need to focus on is : If you use memory to store data , So how to ensure that the data is reloaded after refreshing the page .


Other answers 4:

To get to know store.js Well .

https://github.com/marcuswestin/store.js

Is an implementation of the browser's local storage JavaScript encapsulation API, Not through Cookie and Flash Technical realization , But use localStorage、globalStorage and userData Behavior .

copyright notice
author[segmentfault],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/04/202204290516105500.html

Random recommended