Session/Local Variables for Quasar
I am creating a login page for my application, and I was thinking how can I store my
session variablesuch that the
usernamewill be display on my pages after I have logged in.
I have looked at the
Local/Session Pluginfrom https://quasar.dev/quasar-plugins/web-storage#Introduction but was unclear of how I should implement it in my code.
I have followed and used the code from the documentation in my
<script>tag as shown:
this.$q.localStorage.set(key, value) let value = this.$q.localStorage.getItem(key)
This is a variable that I use to store the
usernamefrom the username input textfield:
var current_username = this.userToSave.username;
Are there any examples I could reference to for the
Local/Session Plugin? And if I used the above code in my login page, how can I access the session variable in my other pages?
Would appreciate some help on this, thank you!
I have figured out how it works!
At login page:
At main page:
let value = this.$q.localStorage.getItem("username")
If I want to logout from my application, do I do the following?
If you clear the localStorage, you’ll remove all data, not only the username. It’s safer to use
I’ll advise you to use
vuexinstead, keep username in the store and use actions to login/logout/authenticate/etc.
@jraez Oh, I see. Will try that, thanks alot for the help!