Code Monkey home page Code Monkey logo

Comments (5)

larenelg avatar larenelg commented on May 28, 2024 1

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.

prazdevs avatar prazdevs commented on May 28, 2024

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.

prazdevs avatar prazdevs commented on May 28, 2024

given the example above, i'll close this for now, feel free to reopen if you need further info :)

from pinia-plugin-persistedstate.

OleMariusKohmann avatar OleMariusKohmann commented on May 28, 2024

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.

prazdevs avatar prazdevs commented on May 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.