pinia-class-component
pinia-class-component copied to clipboard
$reset not resetting the state
Hello! I was experimenting adding $reset
to a setup function store (Composition API style), and found about this lib in the process.
Tried it, and $reset
is not resetting the state. 🤔
My code:
@Store
class AuthStore extends Pinia {
public isAuthenticated: boolean = false
public test: string = 'abc'
public login(): void {
}
public logout(): void {
}
}
let authStore: AuthStore | undefined
export const useAuthStore = () => {
// Had to do this or else I get a getActivePinia not ready error.
if (!authStore) {
authStore = new AuthStore()
}
return authStore
}
Then in pages/index.vue:
<script lang="ts" setup>
const authStore = useAuthStore()
async function handleResetButtonClick(): Promise<void> {
authStore.$reset()
}
onMounted(() => {
authStore.isAuthenticated = true
authStore.test = 'def'
})
</script>