Code Monkey home page Code Monkey logo

Comments (5)

prazdevs avatar prazdevs commented on May 27, 2024

Hi, there are some examples of configuration in the docs:

import { defineStore } from 'pinia'

export const useStore = defineStore('main', {
  state: () => {
    return {
      someState: 'hello pinia',
      nested: {
        data: 'nested pinia',
      },
    }
  },
  persist: {
    key: 'store-key',
    storage: window.sessionStorage,
    paths: ['nested.data'],
    beforeRestore: context => {
      console.log('Before hydration...')
    },
    afterRestore: context => {
      console.log('After hydration...')
    },
  },
})

I'm still in the process of writing proper docs for it. Does that answer your question ?

from pinia-plugin-persistedstate.

zyyv avatar zyyv commented on May 27, 2024

Thanks your reply.
I meet some trouble in Nuxt3. I test use example config with docs, but it can't resolve. So i hope to improve the example.

As for my trouble:
image

I can't see any cache in my cookies about this store, but other store was fine. (I test setup & configure pinia options, but they were unsuccessful )

from pinia-plugin-persistedstate.

Stiropor avatar Stiropor commented on May 27, 2024

Same problem here, not working with Nuxt3 anymore. It worked fine on Friday, after that it's not setting the cookie anymore. I've tried loading plugin as client also, no difference. Maybe something has changed in Nuxt about cookies?

from pinia-plugin-persistedstate.

prazdevs avatar prazdevs commented on May 27, 2024

Can you provide a proper reproduction repo? It still works fine on my side.

from pinia-plugin-persistedstate.

Stiropor avatar Stiropor commented on May 27, 2024

I'm defining the plugin as per documentation, this is my store. This code set the cookie few days ago but doesn't anymore.

import { defineStore } from 'pinia'

export const useCartStore = defineStore({
	id: 'cart-store',
	persist: {
		paths: ['uuid'],
	},
	state: () => ({
		uuid: null,
	}),

	actions: {
		updateCart (payload) {
			this.uuid = payload.uuid
		}
	}
})

I cannot give full repo right now, but will try to make it in following days.

Update: nevermind. I'm using ssr and using a cart store in a module so in some combination my store wasn't imported when loading persistent store in plugin. Works perfectly now 😃

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.