0

i'm using Vuex and vuex-persistedstate in my project.
How can I change time to live(ttl) of local storage in Vue?
Sorry for my bad English P.S. i use this solution When do items in HTML5 local storage expire? .

  • What have you tried so far? – kboul Oct 08 '18 at 07:44
  • Now, i have 2 different solutions for this question. One - use js-cookie in store, second - use solution https://stackoverflow.com/questions/2326943/when-do-items-in-html5-local-storage-expire . Now, i use window.localStorage in my project – Ksenia Subbotina Oct 09 '18 at 12:14

1 Answers1

1

vuex-persistedstate seems to be making use of this cookie library:

https://github.com/js-cookie/js-cookie#expires

This example has the expired property as well(taken from their documentatiion):

const store = new Store({
  // ...
  plugins: [
    createPersistedState({
      storage: {
        getItem: key => Cookies.get(key),
        setItem: (key, value) =>
          Cookies.set(key, value, { expires: 3, secure: true }),
        removeItem: key => Cookies.remove(key),
      },
    }),
  ],
})

The number 3 here is the number of days, if you want less you can follow this FAQ:

https://github.com/js-cookie/js-cookie/wiki/Frequently-Asked-Questions#how-to-make-the-cookie-expire-in-less-than-a-day

Stephan-v
  • 19,255
  • 31
  • 115
  • 201