N
Nuxtβ€’3w ago
ZaKk

delete pinia store data.

hey guys, is there any way to delete one of the pinia stores programatically? for example i want to delete "menu" and "layout" every time a user logs out. using nuxt 3.0.0, vue 3.2.13 and pinia 2.0.34
No description
29 Replies
kogratte
kogratteβ€’3w ago
kogratte
kogratteβ€’3w ago
?
ZaKk
ZaKkβ€’3w ago
i really can't figure out how to use that :S
kogratte
kogratteβ€’3w ago
UseMyStore().$dispose()
ZaKk
ZaKkβ€’3w ago
No description
ZaKk
ZaKkβ€’3w ago
No description
ZaKk
ZaKkβ€’3w ago
No description
kogratte
kogratteβ€’3w ago
I can help you but it won't really help. What about reading the manual as well as js fundamentals re. Scopes? Tips:you cannot dispose something that doesn't exists. And you can't destroy the store from itself, rather from where it is used.
ZaKk
ZaKkβ€’3w ago
hmmm i know i cannot destroy an object from itself, i want to destroy another store from this scope but it seems i can't see the other store from here
kogratte
kogratteβ€’3w ago
Two questions. Why are you stucked with js? Why don't use typescript as well as the new store syntax which is well documented by pinia's team? I bet you'll get better visibility and readability. Re. Your question, it should works as long as you're not disposing this store from the logout. I'm using something similar on a projet and it works well. May it be due to the async modifier?
ZaKk
ZaKkβ€’3w ago
i'm stuck in some parts with JS because the template was built like that, all my code is TS tho.
kogratte
kogratteβ€’3w ago
BTW, defineStore will create a new store, not use an existing one. Could you use an exported ref?
ZaKk
ZaKkβ€’3w ago
disepose is not deleting the data, when i log out the data is still there
kogratte
kogratteβ€’3w ago
:/
ZaKk
ZaKkβ€’3w ago
tried with reset() too and it seems to be the same
ZaKk
ZaKkβ€’3w ago
No description
ZaKk
ZaKkβ€’3w ago
it doesn't seem to delete the data
kogratte
kogratteβ€’3w ago
As you're using option store, does $reset do the trick?
No description
ZaKk
ZaKkβ€’3w ago
reset works but i have to log out twice for it to work, kind of weird...
kogratte
kogratteβ€’3w ago
Sounds like a ref issue or something like that...
ZaKk
ZaKkβ€’3w ago
might be, will have a more deep look into that and the code flow
kogratte
kogratteβ€’3w ago
The ideal would be to understand why this double logout is needed... Can't do that ^^
ZaKk
ZaKkβ€’3w ago
yeah i know mate
kogratte
kogratteβ€’3w ago
Was harsh. Sorry about that. Was missing some ctx.
ZaKk
ZaKkβ€’3w ago
no problem mate πŸ˜‰
kogratte
kogratteβ€’3w ago
Hey Zak! Did you find a way?
ZaKk
ZaKkβ€’3w ago
nope, i think i should rewrite the component that loads the menu and load it dynamically from database
kogratte
kogratteβ€’3w ago
May it be due to a remaining ref to the store you're trying to delete?
ZaKk
ZaKkβ€’3w ago
might be but i wanted to rewrite it anyway xd
Want results from more Discord servers?
Add your server