All jobs / Frontend / web developer / Vue
Frontend / web developer interview question · 1–3 years
In setup, a developer writes const { count } = state, where state is a reactive object. The template shows count, but it never updates.
What went wrong, and what are the fixes?
The strongest answer
Destructuring copied the current number out of the reactive proxy, so the link is lost. Read state.count directly, use toRefs to destructure into refs, or hold the value in a ref from the start
Why it works
Right — reactivity lives on property access through the proxy. A destructured primitive is a plain copy; toRefs keeps the connection.
What a good answer covers
- Reactivity lives on the access.
- Destructured primitives are snapshots.
- Use toRefs or state.count.
- Stores: destructure with storeToRefs.
Answers that fall short
- Close, but not the strongest: Use ref instead of reactive for everything and the problem disappears
A reasonable convention, but know why: a plain value pulled out of any reactive source is a snapshot. - Weak: Vue only tracks changes made inside the template, so the update has to move there
Tracking happens wherever a reactive property is read during render or inside an effect, not only in templates. - Red flag: Call the instance’s forceUpdate after every change so the template is made to re-render
Forcing renders hides the broken link and leaves computed values and watchers still blind to the change.
Who gets asked this
More Vue questions
- 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?
- How do you restructure state, and what rule do you give the team?
- 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…