Menu
CoddyTech

Store Actions and Bounds

Part of the Routing and State section of Coddy's Vue journey. Lesson 33 of 55.

Actions describe store operations and keep shared rules in one place. In an options store, regular action methods use this to access state and other store members. A guard inside an action protects every component that calls it.

actions:{
 add(){this.count++},
 remove(){if(this.count>0)this.count--}
}

Use regular methods when relying on the store-bound this; an arrow function captures a different lexical this. Check boundaries before changing state, and test repeated attempts at a boundary as well as one successful call. Components can focus on user interactions while actions enforce the shared rule.

challenge icon

Challenge

Medium

Implement store actions add and remove. Add increments boxes by one each time. Remove decrements only when boxes is greater than zero. The two components must share the result and the total getter must remain consistent. Use store methods so the boundary rule lives in one place.

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>
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Routing and State