All jobs / Frontend / web developer / Vue

Frontend / web developer interview question · 1–3 years

A user page loads its data in onMounted. Clicking from /users/1 to /users/2 changes the URL, but the page still shows user 1.

Why, and how do you fix it?

The strongest answer

Vue Router reuses the same component instance when only the param changes, so onMounted does not run again. Watch the route param — or take it as a prop and watch that — and refetch

Why it works

Right — same route record, same instance, no remount. React to the param instead of relying on the mount hook.

What a good answer covers

Answers that fall short

Who gets asked this

More Vue questions