Skip to content

Conversation

skirtles-code
Copy link
Collaborator

A new FAQ entry for the question Why is my store cleared when I reload the page?.


Another alternative to consider is 'persisting' the data in the URL. This has other ramifications, such as impacting the browser Back button, but if the requirement is for state to be retained across a browser reload then maybe it should be stored in the page URL? It's usually fairly clear whether this approach is a good fit or not.

For the remainder of this page we're going to focus on client-side persistence, e.g. using cookies, `localStorage` or `sessionStorage`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's nothing down below about cookies, not sure if it's intentionally omitted or it's still WIP (or I'm blind)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I'm blind

It uses localStorage by default, or cookies

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do make a fair point, cookies only get mentioned in passing.

While I didn't include any specific examples of using cookies, the approach is essentially the same as using localStorage or sessionStorage, just with a much worse native API.

The VueUse helper for working with cookies is a bit odd. I'm not sure why it's implemented that way, but I would've expected it to expose a cookie value as a ref. Maybe it's not done that way because cookies can be changed by the server, though that isn't really relevant to the use case we're describing here.

@skirtles-code skirtles-code merged commit 61fee19 into vue-land:main Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants