Home > database >  Get whole state object in pinia action
Get whole state object in pinia action

Time:11-07

How can I get whole state obejct(only the state "values" without actions) inside pinia action? "this" return whole store object.

export const useCounterStore = defineStore('counter', {
  state: () => ({
    count: 0,
    name: "apple",
    color: "green",
  }),
  actions: {
    myaction() {
      const wholeState = state?; // {count: 0, name: "apple", color: "green"}
      console.log(wholestate)'
    },
  },
})

CodePudding user response:

You can use this.$state. Document

  • Related