All jobs / Frontend / web developer / Vue
Frontend / web developer interview question · 3–5 years
A Vue 3 app has one Pinia store holding everything: the logged-in user, every form’s field values, modal open flags and cached API lists.
How do you restructure state, and what rule do you give the team?
The strongest answer
Several stores split by domain. Pinia keeps state that is genuinely shared or must outlive a page; form fields and modal flags go back to local component state; changes go through actions so they are traceable
Why it works
Right — the question for every piece of state is who else needs it and for how long. Global by default makes every component depend on everything.
What a good answer covers
- Global only when it is shared.
- Stores by domain, not one bucket.
- Local state for forms and toggles.
- Mutate through actions.
Answers that fall short
- Close, but not the strongest: Split the one big store into a few smaller stores by feature, keeping the same contents
Smaller files, same problem: a modal flag does not become shared state by moving to a smaller store. - Weak: Remove Pinia and pass everything through props and emits from the root component
Auth and cached lists really are shared; pushing them through ten layers of props trades one mess for another. - Red flag: Keep the single store and let any component write any field directly, since that is the fastest to code
Unrestricted writes to one global object is how nobody can say which screen broke the cart.
Who gets asked this
More Vue questions
- A five-year-old Vue codebase is on Vue 3 but written entirely in the Options API with mixins and Vuex. Some…
- A child component receives a quantity prop and has plus and minus buttons. In Vue, how should the child…
- In a Vue 3 component using script setup, you try to focus an input through a template ref at the top of setup…
- In setup, a developer writes const { count } = state, where state is a reactive object. The template shows…
- In Vue, when do you use a computed property and when a watcher?
- A user page loads its data in onMounted. Clicking from /users/1 to /users/2 changes the URL, but the page…
- What is wrong with the composable, and what is the contract a composable should follow?