All jobs / Frontend / web developer / Vue
Frontend / web developer interview question · 0–1 years
A child component receives a quantity prop and has plus and minus buttons.
In Vue, how should the child change the quantity?
The strongest answer
It must not mutate the prop. It emits an event with the new value and the parent updates its own state — or the pair is wired with v-model, which is the same prop-plus-event contract
Why it works
Right — one-way data flow: props down, events up. v-model on a component is sugar for exactly that.
What a good answer covers
- Props down, events up.
- Never mutate a prop.
- Emit the new value.
- v-model is prop plus event.
Answers that fall short
- Close, but not the strongest: Copy the prop into a local ref and change that copy inside the child
The warning goes away, but now there are two quantities and the parent’s is stale. - Weak: Change props.quantity directly; Vue’s reactivity will carry it up to the parent
Props are read-only in the child; Vue warns, and the parent’s next render overwrites the change. - Red flag: Reach into the parent instance from the child and set its data there
Reaching into the parent couples the child to one specific parent and makes the data flow impossible to follow.
Who gets asked this
More Vue questions
- 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?
- 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…