Using a Class to declare all getters and actions #2348
Unanswered
dominicmeyer
asked this question in
Help and Questions
Replies: 1 comment 3 replies
-
import { defineStore } from 'pinia'
import { ref } from 'vue'
export class TestCollection {
public logs: string[] = []
public message: string = ''
public test(): void {
this.logs.push(this.message)
this.message = ''
}
public clear(): void {
this.logs = []
}
}
export const useTestStore = defineStore('test', () => {
const testCollection = new TestCollection()
return {
testCollection,
}
}) Usageconst {testCollection} = useTestStore()
testCollection.test()
testCollection.clear() You can't destructure a ref or it loses reactivity. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I wanna declare a store like this and use the methods of the class, without writing it manually again.
This would useful, to use Inheritance and Interfaces for the return values.
The example below isn't working, is there another way of doing this?
Some Component:
Beta Was this translation helpful? Give feedback.
All reactions