rendom
rendom

Reputation: 3705

Get whole state object in pinia action

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)'
    },
  },
})

Upvotes: 1

Views: 1834

Answers (1)

Duannx
Duannx

Reputation: 8726

You can use this.$state. Document

Upvotes: 3

Related Questions