Search code examples
vue.jsvueuse

How do you specify if storage should be local or session when using VueUse?


How do you specify if storage should be local or session when using VueUse?

It doesn't seem to mention it in the docs https://vueuse.org/core/usestorage/


Solution

  • The third argument to useStorage() specifies the storage to use. It uses window.localStorage by default.

    To use session storage, pass window.sessionStorage as the storage argument:

    useStorage(
      'my-storage-key',
      myInitialValue,
      window.sessionStorage, 👈
    )