Skip to content

Can I use computed inside a Pinia store? #1765

Discussion options

You must be logged in to vote

Yes, that's exactly how to define a getter

note you also need to return the state for it be picked up by devtools and, more importantly, for SSR:

return {
  ...toRefs(state),
  prefixed,
  withAge,
  // you don't need a setName action if it just sets the name
}

Also worth seeing: https://pinia.vuejs.org/core-concepts/state.html#resetting-the-state

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@rodrigocfd
Comment options

Answer selected by posva
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants