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

1.7k views Asked by At

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/

1

There are 1 answers

0
tony19 On BEST ANSWER

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, 
)