How can vue.js keep the login status when writing spa applications?

how can vue.js keep its login status when writing spa applications?

Mar.04,2021

generally, after the background verifies that the user name and password are correct, a code, server that generates the user login status is saved with session, and the front end is saved with cookie. This is operated by the server, not the front end. Because each http request will also automatically take the cookie, server to compare the value of cookie in the request with the value in session to confirm the login status of the user. This is the principle of the login state. It has nothing to do with vue.js writing spa applications. It's all the same way.


generally, the backend will return a token value in the foreground. You can store this value in cookice or sessionstorage, or you can use vuex to obtain it (it is not recommended to save it directly in vuex. In this way, a refreshed page will lose), and every time you need to request data from the backend, bring this token to the backend to check whether the token is correct and expired. Then send you the corresponding data

Menu