"How to use Pinia in a TypeScript class?" #2714
Unanswered
JHeLiu
asked this question in
Help and Questions
Replies: 1 comment
-
Just use Composition API: import { storeToRefs } from 'pinia'
const useUserStore = defineStore('user', {
state: () => ({
name: 'Jane'
})
})
export class UserContext {
static add(id: string) {
const userStore = useUserStore()
const { name } = storeToRefs(userStore)
console.log(name.value) // It is imported as a Vue ref so you need to call `.value`
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Beta Was this translation helpful? Give feedback.
All reactions