Technology

Vue.js Interview Questions and Answers

Vue.js is a progressive JavaScript framework popular with startups and product companies. These Vue.js interview questions cover templates, directives, components and props for freshers, then the Composition API, reactivity, computed vs watch, Pinia, Vue Router, Nuxt and performance for experienced Vue developers.

30 questions · Updated

Reading answers is not the same as saying them.Practise Vue.js questions out loud and get a score, what you missed and a model answer for each one.
Practise free with AI
Vue.js Interview Questions with answers. Examples: What is Vue.js, and what makes it popular? What are the common Vue directives? What is the difference between v-if and v-show? What is the difference between the Options API and the Composition API?
Vue.js Interview Questions: 30 questions with model answers on this page.

Basic Vue.js interview questions

Fundamentals, definitions and simple scenarios. Good for freshers and warm-ups.

1. What is Vue.js, and what makes it popular?

Vue.js is a progressive JavaScript framework for building user interfaces. It is easy to learn because templates look like HTML, it can be added to part of an existing page or used for a full single-page app, and it has an efficient reactivity system, single-file components and official libraries for routing (Vue Router) and state (Pinia).

2. What are the common Vue directives?

v-bind (shorthand :) binds attributes and props, v-on (shorthand @) listens to events, v-model creates two-way binding on form inputs and components, v-if, v-else-if and v-else render conditionally, v-show toggles visibility with CSS, v-for renders lists and needs a unique :key, and v-html renders raw HTML, which must only be used with trusted content.

3. What is the difference between v-if and v-show?

v-if adds and removes the element from the DOM, so it has a higher toggle cost but nothing is rendered when false. v-show always renders the element and toggles display: none, so it has a higher initial cost but cheap toggling. I use v-show for things toggled often and v-if for conditions that rarely change.

4. How do you create and mount a Vue application?

Call createApp with the root component, register plugins such as the router and Pinia with app.use(), and mount it on an element: createApp(App).use(router).mount("#app"). Projects are usually created with npm create vue@latest, which sets up Vite, TypeScript, the router, Pinia and testing as you choose.

5. What is a single-file component?

Answer flow · 4 steps
  1. A .vue file that keeps a component's template, script and styles together in <template>, <script setup> and <style> blocks.

  2. Adding scoped to the style block limits the CSS to that component.

  3. Build tools such as Vite compile these files.

  4. Keeping everything for one component in one file makes it easy to understand and maintain.

6. How do you validate props in Vue?

Answer flow · 3 steps
  1. With <script setup> and TypeScript, defineProps<{ title: string; count?: number }>() gives type checking.

  2. Without TypeScript, defineProps accepts an object with type, required, default and a custom validator function for each prop.

  3. Props should be treated as read-only; to change a value the child emits an event or copies it into local state.

7. What are Vue's lifecycle hooks?

In the Composition API: onBeforeMount and onMounted (the component is in the DOM, good for DOM access and starting things), onBeforeUpdate and onUpdated (after reactive changes re-render), and onBeforeUnmount and onUnmounted (clean up timers, listeners and subscriptions). onErrorCaptured catches errors from children. Setup code itself runs before mounting.

8. How do event handling and event modifiers work?

v-on, or @ for short, listens to events: @click="save" or @input="onInput". Modifiers handle common needs without extra code: .prevent calls preventDefault, .stop stops propagation, .once runs the handler once, .self ignores events from children, and key modifiers such as @keyup.enter react to specific keys.

9. Why does v-for need a key?

Answer flow · 3 steps
  1. The key gives each item a stable identity, so when the list changes Vue can reuse, move and remove the right elements instead of patching them in place.

  2. Without unique keys, component state and input values can stay attached to the wrong item when you sort, filter or delete.

  3. Use an id from the data, not the index.

10. How do you bind classes and styles dynamically?

:class accepts a string, an object such as { active: isActive, disabled: !canEdit } or an array of these, and merges with any static class. :style accepts an object of CSS properties, such as { color: textColor, width: progress + "%" }. Computed properties keep complex class logic out of the template.

11. What are slots?

Slots let a parent pass template content into a child component. The default slot receives content placed between the tags, named slots such as <template #header> fill specific areas, and scoped slots let the child pass data back to the parent's template, for example a table component giving each row to the parent to render.

Intermediate Vue.js interview questions

Applied problems, trade-offs and questions about your own projects.

12. What is the difference between the Options API and the Composition API?

Answer flow · 3 steps
  1. The Options API organises a component into options such as data, methods, computed and watch.

  2. The Composition API, used with <script setup>, organises code by feature using functions such as ref, reactive, computed and watch.

  3. It makes logic easier to reuse through composables and works better with TypeScript, so it is the recommended choice for new Vue 3 projects.

13. What is the difference between ref and reactive?

ref wraps any value, including primitives, in an object with a .value property; templates unwrap it automatically. reactive makes an object deeply reactive using a Proxy but cannot hold primitives, and loses reactivity if you destructure it or replace the whole object. Many teams use ref everywhere for consistency.

14. What is the difference between computed and watch?

Answer flow · 3 steps
  1. A computed property derives a value from reactive state and is cached until its dependencies change, which suits values shown in the template, such as a filtered list.

  2. A watcher runs a side effect when a source changes, such as fetching data when a search term changes or saving to local storage.

  3. If you are just calculating a value, use computed.

15. How do components communicate in Vue?

Answer flow · 3 steps
  1. Parents pass data to children through props, and children notify parents by emitting events with defineEmits. v-model on a component combines a prop and an update event.

  2. For deep trees, provide and inject pass data without prop drilling, and for shared application state Pinia stores are used.

  3. Slots let parents pass template content into children.

16. What is the difference between watch and watchEffect?

watch explicitly lists the sources to watch, gives you the old and new values, and is lazy by default (it runs only when the source changes, unless immediate: true). watchEffect runs immediately and automatically tracks every reactive value used inside it. watch suits reacting to one specific change, such as fetching data when an id changes; watchEffect suits effects that depend on several values.

17. What are composables?

Answer flow · 4 steps
  1. Composables are functions that use the Composition API to package reusable stateful logic, named with a use prefix, such as useMouse, useFetch or useLocalStorage.

  2. Each component that calls one gets its own reactive state.

  3. They replace mixins, which had unclear origins of properties and name clashes.

  4. VueUse is a popular library of ready-made composables.

18. What is Teleport?

<Teleport to="body"> renders part of a component's template somewhere else in the DOM, while it stays part of the component logically, with access to its state and events. It is used for modals, notifications and tooltips that must escape parent elements with overflow: hidden or stacking contexts.

19. What are dynamic and async components, and what does KeepAlive do?

<component :is="currentTab"> switches between components dynamically. defineAsyncComponent loads a component only when it is needed, which splits code and speeds up initial load. <KeepAlive> caches inactive components instead of destroying them, so tab content keeps its state and does not reload; onActivated and onDeactivated hooks run when they are shown or hidden.

20. What are Vue Router navigation guards?

Answer flow · 3 steps
  1. Guards control navigation. router.beforeEach runs before every route change and is used for authentication, for example redirecting to the login page when route meta says it requires auth.

  2. Per-route beforeEnter guards and in-component guards such as onBeforeRouteLeave, which can warn about unsaved changes, handle more specific cases.

  3. A guard returns false to cancel or a route to redirect.

21. What are custom directives?

Answer flow · 3 steps
  1. Custom directives add low-level DOM behaviour to elements, defined with hooks such as mounted, updated and unmounted.

  2. In <script setup>, any variable named vSomething becomes a directive, such as vFocus for auto-focusing an input.

  3. Use them for direct DOM access, such as focus, click-outside detection or intersection observers; most logic belongs in components or composables.

22. What do defineProps, defineEmits, defineExpose and defineModel do?

They are compiler macros used in <script setup> without importing. defineProps declares props, defineEmits declares events the component can emit, defineExpose chooses what a parent can access through a template ref (components are closed by default), and defineModel creates a two-way binding prop that works with v-model on the component with very little code.

High level Vue.js interview questions

System design, deep internals, leadership and tough follow-ups.

23. How does Vue's reactivity system work?

Answer flow · 4 steps
  1. Vue 3 wraps reactive objects in JavaScript Proxies.

  2. When a component renders or a computed property runs, Vue tracks which reactive properties are read.

  3. When one of those properties is set, Vue triggers only the effects that depend on it, and batches DOM updates to the next tick.

  4. Combined with a compiler that marks static parts of templates, this makes updates efficient.

24. What is Pinia, and why did it replace Vuex?

Answer flow · 4 steps
  1. Pinia is the official state management library for Vue.

  2. Stores define state, getters and actions, with no separate mutations, which makes it simpler than Vuex.

  3. It has full TypeScript support, works with the Composition API, supports multiple modular stores, devtools and server-side rendering.

  4. Vuex is now in maintenance mode.

25. What is Nuxt, and when would you use it?

Nuxt is a framework built on Vue that adds file-based routing, server-side rendering, static generation, hybrid rendering per route, auto-imports, server API routes and SEO helpers. I use it when a Vue application needs good SEO and fast first load, such as marketing sites, blogs and e-commerce, or when I want conventions for a large app.

26. What changed between Vue 2 and Vue 3?

Vue 3 added the Composition API and <script setup>, a Proxy-based reactivity system that detects added properties and array index changes, better TypeScript support, smaller and faster builds with tree-shaking, fragments (multiple root nodes), Teleport and Suspense. createApp replaced new Vue, filters were removed, and Pinia replaced Vuex. Vue 2 reached end of life at the end of 2023.

27. How do you optimise a Vue application?

Lazy-load routes and heavy components, use v-memo and v-once for parts that rarely change, shallowRef and shallowReactive for large data that does not need deep reactivity, computed properties instead of methods in templates, virtual scrolling for long lists, and stable keys. I measure with Vue Devtools and Lighthouse, and keep bundles small by checking dependencies.

28. How do server-side rendering and hydration work in Vue?

Answer flow · 3 steps
  1. With Nuxt or Vue's own SSR APIs, the server renders components to HTML for fast first load and SEO, and the client hydrates it, attaching reactivity and event listeners.

  2. Server and client output must match, so browser-only code goes in onMounted or <ClientOnly>.

  3. State fetched on the server is passed to the client so data is not loaded twice.

29. How do you test Vue components?

Answer flow · 3 steps
  1. Use Vitest with Vue Test Utils or Testing Library for Vue: mount the component, interact with it as a user would, and assert on the rendered output and emitted events.

  2. Pinia stores can be tested directly or replaced with createTestingPinia, and API calls are mocked with MSW.

  3. End-to-end tests with Playwright or Cypress cover full user journeys.

30. How do you use TypeScript with Vue?

Answer flow · 3 steps
  1. Use <script setup lang="ts"> and type props with defineProps<Props>(), events with defineEmits, refs with ref<User | null>(null) and template refs with useTemplateRef.

  2. Run type checking with vue-tsc, since Vite only strips types.

  3. Pinia stores, composables and the router are fully typed, and the Vue - Official extension gives type checking inside templates.

Ready to test yourself?Pick your topics and level, answer by voice or text, and get instant feedback. Free.
Start a mock interview

Preparing for a frontend developer interview?

See all Frontend Developer interview questions, covering HTML, CSS, JavaScript, TypeScript, React and more.

Related skill interview questions

More technology interview questions

HR round, company and bank interview questions

Bank and government exams

Interview questions for other fields