We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
In Option Stores, you can reset the state to its initial value by calling the $reset()
method on the store:
const store = useStore()
store.$reset()
Internally, this calls the state()
function to create a new state object and replaces the current state with it.
In Setup Stores, you need to create your own $reset()
method:
export const useCounterStore = defineStore('counter', () => {
const count = ref(0)
function $reset() {
count.value = 0
}
return { count, $reset }
})
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.