Comments (5)
I'm not sure about Cookies, but I hope this helps for Nuxt 2:
plugins/persistedStatePlugin.js
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
const persistedStatePlugin = ({ $pinia }) => {
$pinia.use(piniaPluginPersistedstate)
}
export default persistedStatePlugin
nuxt.config.js
plugins: [
'~/plugins/persistedStatePlugin.js'
],
from pinia-plugin-persistedstate.
Hey :)
useCookie is a nuxt3 specific composable, and so is the createNuxtPersistedState
factory.
You can use it with nuxt2 by making it a client side only plugin. I don't know much about cookies on nuxt2 though.
from pinia-plugin-persistedstate.
given the example above, i'll close this for now, feel free to reopen if you need further info :)
from pinia-plugin-persistedstate.
I'm not sure about Cookies, but I hope this helps for Nuxt 2:
plugins/persistedStatePlugin.js
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate' const persistedStatePlugin = ({ $pinia }) => { $pinia.use(piniaPluginPersistedstate) } export default persistedStatePlugin
nuxt.config.js
plugins: [ '~/plugins/persistedStatePlugin.js' ],
Added this to the project and the following error occurs when accessing app on localhost after npm run dev:
ERROR localStorage is not defined 16:33:45
at node_modules\pinia-plugin-persistedstate\dist\index.js:86:17
at node_modules\pinia\dist\pinia.cjs:1590:43
at EffectScopeImpl.run (node_modules\@vue\composition-api\dist\vue-composition-api.common.js:110:24)
at node_modules\pinia\dist\pinia.cjs:1590:33
at Array.forEach (<anonymous>)
at createSetupStore (node_modules\pinia\dist\pinia.cjs:1577:14)
at createOptionsStore (node_modules\pinia\dist\pinia.cjs:1168:13)
at useStore (node_modules\pinia\dist\pinia.cjs:1654:17)
at asyncData (node_modules/vue-loader/lib/index.js:85:0)
at promisify (.nuxt/utils.js:314:0)
at server.js:4105:82
at Array.map (<anonymous>)
at module.exports../.nuxt/server.js.__webpack_exports__.default (.nuxt/server.js:245:0)
from pinia-plugin-persistedstate.
name your file plugins/persistedStatePlugin.client.js
to make it clientside only, that way it won't try to access to localStorage while server side rendering
from pinia-plugin-persistedstate.
Related Issues (20)
- Persistence doesn't work? HOT 3
- How to handle this warning? Inconsistent rendering between server and client HOT 3
- reactive([1]) Unable to deserialize properly HOT 2
- Save to store after X seconds of no further changes. HOT 1
- Having interval inside a persistent store breaks persisting
- [pinia-plugin-persistedstate] Error: [nuxt] A composable that requires access to the Nuxt instance was called outside of a plugin HOT 2
- In the cookie store defineNuxtRouteMiddleware method was used in nuxt3 unable to get to the store of value HOT 3
- Critical security vulnerability? HOT 6
- nuxt bug Cannot read properties of undefined (reading 'sessionStorage') HOT 1
- Automatically set `Vary: Cookie` response header in Nuxt SSR
- pinia.use(piniaPersist) in a separate file, causing local storage to fail HOT 2
- Missing "./package.json" export HOT 1
- Not effective when working with vee-validate
- Global `cookieOptions` are not applied in Nuxt 3 HOT 1
- Type safe persist paths HOT 2
- Store not hydrated from cookies when used with `@nuxtjs/i18n` and `routeRules`
- Using store outside setup(), state persistence is not possible HOT 1
- The type of map print in console.log (typeof this.userMap) is object HOT 1
- Persist for "composition api" style HOT 1
- 配置 storage: persistedState.sessionStorage 会导致 v-bind 失效
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pinia-plugin-persistedstate.