Menu
CoddyTech

Setup Store Structure

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

A setup store expresses its state with refs, its getters with computed values and its actions with functions. Return those members so Pinia can track and expose them. This style uses Composition API tools you already know.

export const useTimerStore=defineStore('timer',()=>{
 const minutes=ref(5);
 const seconds=computed(()=>minutes.value*60);
 function extend(){minutes.value++}
 return {minutes,seconds,extend};
});

Inside the setup function, refs still use .value. Outside, the reactive store unwraps them. Return all state properties rather than hiding private store state; Pinia needs those returned members for state management. Ordinary temporary component drafts can still remain outside the store.

challenge icon

Challenge

Medium

Implement the setup-style usePlanStore. Declare seats ref 1 and room ref Small, a computed label room: seats, and an add action. Return every state ref, the computed value and the action from the store. The supplied room toggle and repeated add clicks must update both readouts.

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