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
29 Replies
Pinia π
Intuitive, type safe, light and flexible Store for Vue
?
i really can't figure out how to use that :S
UseMyStore().$dispose()
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.
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
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?
i'm stuck in some parts with JS because the template was built like that, all my code is TS tho.
BTW, defineStore will create a new store, not use an existing one. Could you use an exported ref?
disepose is not deleting the data, when i log out the data is still there
:/
tried with reset() too and it seems to be the same
it doesn't seem to delete the data
As you're using option store, does $reset do the trick?
reset works but i have to log out twice for it to work, kind of weird...
Sounds like a ref issue or something like that...
might be, will have a more deep look into that and the code flow
The ideal would be to understand why this double logout is needed... Can't do that ^^
yeah i know mate
Was harsh. Sorry about that. Was missing some ctx.
no problem mate π
Hey Zak! Did you find a way?
nope, i think i should rewrite the component that loads the menu
and load it dynamically from database
May it be due to a remaining ref to the store you're trying to delete?
might be but i wanted to rewrite it anyway xd