Unable to persist state ^1.6.1
See original GitHub issueHI, I have created fresh Nuxt 3 project with these dependencies.
"devDependencies": { "@nuxt/content": "^2.0.1", "nuxt": "3.0.0-rc.4", "tailwindcss": "^3.1.6" }, "dependencies": { "@heroicons/vue": "^1.0.6", "@nuxt/types": "^2.15.8", "@nuxt/typescript-build": "^2.1.0", "@pinia/nuxt": "^0.2.0", "pinia": "^2.0.15", "pinia-plugin-persistedstate": "^1.6.1" }
this is a plugin that I have followed by .md instructions for Nuxt.
import { createNuxtPersistedState } from 'pinia-plugin-persistedstate' import { defineNuxtPlugin, useCookie } from '#app' export default defineNuxtPlugin(nuxtApp => { nuxtApp.$pinia.use(createNuxtPersistedState(useCookie)) })
this is my nuxt.config.ts
modules: ['@pinia/nuxt', '@nuxt/content'], plugins: [ {src: '~/plugins/pinia-persisted.client.ts', mode: 'client'} ]
this is my state/index.ts
import { defineStore } from 'pinia' export const useFiltersStore = defineStore('my-store', () => { const counter = ref<number>(0); return { counter } },{ persist: true })
Can you point out if I made some mistake or if I am missing something? I have no errors with pinia, state is working as expected just I am unable to have persisted state for ‘my-state’.
Thank you!
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
AAA JUUU! It works! You saved me from a lot of trouble. Thank you so much!
Ok, so if you use the latest versions of nuxt (rc-5), @pinia/nuxt (0.3.0) and pinia (2.0.16), and use the config given in https://github.com/prazdevs/pinia-plugin-persistedstate/tree/main/examples/nuxt i think if should work ?
side notes:
nuxt.config.ts
, don’t usebuildModules
but usemodules
instead.nuxt.config.ts
.client
is you use the helper with useCookie.oh, and i had no idea there was a ‘pinia-plugin-persistedstate-2’ 😂 not mine so i can’t help with it 😄