Vue Middle interview questions and answers
75 questions for a Vue (Middle) interview - with correct answers, explanations and links to the docs.
Take this quiz- 1.Why doesn't this watcher fire?
- 2.How does
watchEffectdiffer fromwatch? - 3.How do you cancel a stale request when a watched
idchanges quickly (Vue 3.5+)? - 4.What does
{ deep: true }do on a watcher? - 5.When is
shallowRefa better choice thanref? - 6.What does
toRefsdo? - 7.What is a writable computed?
- 8.Why is mutating state inside a computed getter a bug?
- 9.How do you make a
watchcallback also run right away with the current value? - 10.When does a watcher with
flush: 'post'run? - 11.What do
defineModelmodifiers let you do? - 12.How do you apply fallthrough attributes to an inner element instead of the root?
- 13.What is a scoped slot?
- 14.How do you keep provided state reactive but prevent descendants from mutating it?
- 15.Why use an
InjectionKeysymbol instead of a string forprovide/inject? - 16.What does
defineAsyncComponentdo? - 17.What does
defineExposedo in<script setup>? - 18.What does the 3.5 reactive props destructure allow?
- 19.How do you type component events with TypeScript?
- 20.What is a composable?
- 21.What problems of mixins do composables solve?
- 22.How should a composable accept arguments that might be refs, getters or plain values?
- 23.Why must composables be called synchronously in
<script setup>rather than in a callback? - 24.What happens when
<script setup>contains a top-levelawait? - 25.How do you write a local custom directive in
<script setup>? - 26.What is a Vue plugin?
- 27.What does
<KeepAlive>do? - 28.Why render a modal with
<Teleport to="body">? - 29.How does
<Transition name="fade">animate an element? - 30.What problem does
nextTicksolve here? - 31.How do you lazy-load a route component?
- 32.How do you protect routes that require authentication?
- 33.Why doesn't the page update when navigating from
/users/1to/users/2? - 34.What does
props: truein a route definition do? - 35.Why does reloading
/aboutreturn 404 in production withcreateWebHistory? - 36.What is the difference between
router.pushandrouter.replace? - 37.How are nested routes rendered?
- 38.Why does destructuring a Pinia store lose reactivity, and how is it fixed?
- 39.What is the difference between setup stores and option stores in Pinia?
- 40.What does
store.$patchoffer? - 41.Can Pinia actions be asynchronous?
- 42.How do you use a store outside of a component, e.g. in a router guard?
- 43.Why isn't this Pinia getter cached?
- 44.How can one Pinia store use another?
- 45.How do you style an element inside a child component from a scoped style?
- 46.What does
v-bind()inside<style>do? - 47.How do you catch errors from descendant components?
- 48.Why
awaituser interactions in Vue Test Utils? - 49.How do you test a component that uses Pinia stores?
- 50.Which tool type-checks
.vuefiles, including templates, in CI? - 51.How do you animate items being added, removed and reordered in a list?
- 52.Why prefer local imports over global
app.component()registration? - 53.How do you set component options like
inheritAttrs: falsein<script setup>? - 54.How do you watch several sources with one callback?
- 55.What does
{ once: true }do on a watcher (Vue 3.4+)? - 56.How do you stop a watcher before the component unmounts?
- 57.How can you create a ref that debounces updates?
- 58.You mutate an array inside a
shallowRef. Why doesn't the view update, and how do you fix it? - 59.What does
<Suspense>do with a component that has a top-levelawaitin<script setup>? - 60.How do you warn the user before leaving a route with unsaved changes?
- 61.What are the two common ways to load data for a route?
- 62.How do you keep filters in the URL query and react to their changes?
- 63.What are named views in Vue Router?
- 64.How does a route
aliasdiffer from aredirect? - 65.How do you know whether
router.push()actually navigated? - 66.Does a setup store have
$reset()like an option store? - 67.How do you log every action of a Pinia store and its errors?
- 68.What does VueUse provide?
- 69.What do CSS Modules in an SFC look like?
- 70.How do you style slot content passed in by the parent from a component's scoped styles?
- 71.When is
shallowMountuseful in Vue Test Utils? - 72.In a component test, why
await flushPromises()after clicking a button that triggers an API call? - 73.What should happen to focus after client-side navigation in an SPA for accessibility?
- 74.How do you run a Vite build with settings from
.env.staging? - 75.Why should production builds use Vue's production mode?