Resetting Store State
Part of the Routing and State section of Coddy's Vue journey. Lesson 38 of 55.
An options store has a built-in $reset() that recreates its initial state from the state factory. A setup store instead defines its own reset function, assigning initial values to its refs. Choose the correct reset contract for the store style.
const minutes=ref(5);
const running=ref(false);
function reset(){minutes.value=5;running.value=false}
return {minutes,running,reset};Reset every source field that belongs to the operation. Derived computed values then update automatically. A partial reset can leave the UI in an inconsistent combination, so exercise reset after changing multiple fields and confirm that normal actions still work afterward.
Challenge
MediumAdd a reset action to the setup-style plan store. Restore both seats to 1 and room to Small. The computed label must reflect the reset, and the normal controls must still work afterward. Setup stores define their own reset operation; this task does not call the options-store $reset method.
Keep the supplied route readout and bootstrap files.
Try it yourself
<!doctype html><html><head><meta charset="UTF-8"><title>Routing practice</title></head><body><div id="app"></div><script type="module" src="./main.js"></script></body></html>This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Routing and State
4Query State
Reading Query ValuesCommitting Search QueriesPreserving Other FiltersNormalizing Query NumbersRecap: Catalog Filters2Navigation Actions
Navigation from HandlersReplacing HistoryHistory TravelCurrent Navigation LinksRecap: Save and Review5Nested Layouts
Parent and Child OutletsDefault Child ViewsRelative Child PathsAncestor Navigation StateRecap: Library Workspace8Store Design
Setup Store StructurePatching Related StateResetting Store StateComposing Related StoresRecap: Trip Pack11Workshop Planner Project
Planner RoutesShared Reservations