soc221b / pinia-plugin-persistedstate-2

Persist and rehydrate your Pinia state between page reloads.
https://www.npmjs.com/package/pinia-plugin-persistedstate-2
MIT License
91 stars 8 forks source link

ASK - how to implement using vue vite without nuxt on cookies storage? #34

Closed syukriyansyah-ipb closed 2 years ago

soc221b commented 2 years ago

It's similar to https://github.com/iendeavor/pinia-plugin-persistedstate-2/tree/main/examples/nuxt-bridge-example:

import cookie from 'js-cookie'

const persistedStatePlugin = createPersistedStatePlugin({
  storage: {
    getItem: async (key) => {
      return cookie.get(key)
    },
    setItem: async (key, value) => {
      cookie.set(key, value)
    },
    removeItem: async (key) => {
      return cookie.remove(key)
    },
  },
})

// ...

https://github.com/iendeavor/pinia-plugin-persistedstate-2#storage