PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, October 17, 2022

[FIXED] How to get the whole pinia state object?

 October 17, 2022     pinia, vue.js, vuejs3     No comments   

Issue

I'm trying to have a getter that return all state properties of my pinia store.

export const useFilterStore = defineStore('filterStore', {
    state : () : FilterState => ({
        variables:[] as string[],
        categories:[] as string[]
    }),


    getters: {
        getFilters: (state) => state
    },
    actions : {}
  });

Doing it this way , getFilters references itself generating circular reference on different situation, as illustrated in this component

import { useFilterStore } from './store/filter-store.js'
export default {
  name: 'App',

  setup() {
    const filter = useFilterStore()
    JSON.stringify(filter.getFilters)  --> cyclic object value
  }
}

Is there a way to set up a getter for the whole state object directly?


Solution

getFilters doesn't serve a good purpose. state is the whole store, not just state data, accessing state.getFilters results in a recursion.

It should be:

 JSON.stringify(filter.$state)


Answered By - Estus Flask
Answer Checked By - Terry (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing