Vue.js Core Architecture, Composition API & Reactivity Engine Master Interview Bank
Vue Proxy-based reactivity engine (ref, reactive, effectScope), Composition API, Vapor Mode (VDOM-less compilation), Pinia state architecture, and hydration.
Curriculum Roadmap & Learning Path
3 StagesPart 1: Basic & Foundational Concepts (Junior / Entry-Level)
12 QuestionsWhat is Vue 3 and what are the main differences between the Options API and Composition API?
Options API (Vue 2 & Vue 3 Legacy) • Code is split across predefined options blocks: data(), methods, computed, watch, mounted() • Limitation: In complex components, logic for a single feature (e.g. user search) is fragmented across 5 different options blocks, forcing • Composition API (Vue 3 Modern Standard).
How does Vue 3's Proxy-based Reactivity System work compared to Vue 2?
Vue 2 (Object.defineProperty) • Intercepted properties using getters and setters • Severe Limitations: Could not detect dynamically added or deleted properties (this.obj.newProp = 123 required Vue.set()), and could not detect • Vue 3 (Proxy).
What is the difference between `ref()` and `reactive()` in Vue 3?
ref(value) • Works with primitives (strings, numbers, booleans) as well as objects • Wraps the value in a reactive container object with a .value property • In , you must access .value (count.value++); in , Vue unwraps it automatically ({{ count }}).
How do `computed()` and `watch()` work in Vue 3?
computed(() => ...) • Derives a new reactive value from existing state • Cached: Recomputes only when its reactive dependencies change • Read-only by default (can define custom getter/setter).
What is `watchEffect()` and how does it differ from `watch()`?
watch(source, cb) • You must explicitly define what state to watch (watch(userId...)) • Separates the watched dependency from the side effect • watchEffect(cb).
What is the `<script setup>` syntax sugar?
`` is the compiled syntactic sugar for using the Composition API inside Single-File Components (SFCs): No boilerplate: Top-level variables, functions, and imports are automatically exposed to the template without an explicit export default {.
What are the essential Vue 3 Lifecycle Hooks?
In the Composition API, lifecycle hooks are imported and invoked inside setup(): onMounted(): Component has finished initial rendering and DOM nodes are accessible • onUpdated(): DOM has updated following a reactive state mutation • onUnmounted(): Component has been destroyed and removed from DOM.
How does Two-Way Data Binding work with `v-model` and `defineModel()`?
In Vue 2: v-model was limited to a single property (value + input event) • In Vue 3: A component can have multiple v-model bindings.
What are `defineProps` and `defineEmits` in `<script setup>`?
Compiler macros (no need to import them!) used to declare component API contracts.
`v-if` vs. `v-show`: Performance and DOM Differences.
v-if (Conditional Rendering) • "Real" conditional rendering: elements are physically added or removed from the DOM • Destroys and recreates child component instances and triggers lifecycle hooks (onMounted / onUnmounted) • High toggle cost; low initial render cost if condition is false.
How do Slots, Named Slots, and Scoped Slots work in Vue 3?
Default Slot: Injects child content (``) • Named Slots (#name): Injects content into specific slots.
What is the native `<Teleport>` component?
Allows you to render a component's DOM subtree into a different location in the DOM outside the component hierarchy (typically body), while preserving the component's logical parent-child state and event communication.
Part 2: Core Architecture & Implementation (Mid-Level)
12 QuestionsWhat is Pinia and why did it replace Vuex?
Pinia is the official state management library for Vue 3: No Mutations: In Vuex, modifying state required writing verbose mutations and actions • First-Class TypeScript: 100% type-safe autocomplete without magic strings or complex generic wrappers.
How do you structure Composables in Vue 3?
A Composable is a function that leverages Vue's Composition API to encapsulate and share stateful logic.
What are Template Refs in the Composition API?
Direct access to rendered DOM elements or child component instances.
Dependency Injection with `provide()` and `inject()`.
Passes state from an ancestor component down to deeply nested children without prop drilling.
What is `<KeepAlive>` and its lifecycle hooks?
Caches inactive component instances in memory rather than destroying them when switching views.
What are Custom Directives in Vue 3?
Low-level DOM manipulation abstractions.
Optimizing Performance with `shallowRef()` and `shallowReactive()`.
Standard ref() and reactive() recursively convert all nested properties into Proxies. If you fetch a massive array of 50,000 read-only table records from an API: Deep reactivity creates 500,000 Proxies, burning memory and freezing the browser • shallowRef(massiveArray): Only tracks .value reassignment.
What is `v-memo` and how does it optimize virtual DOM sub-tree updates?
Introduced in Vue 3.2, v-memo="[dep1, dep2]" memoizes a chunk of the template.
Preserving Reactivity: `toRef()`, `toRefs()`, and `toValue()`.
Destructuring a reactive object breaks reactivity: const { count } = state; -> loses proxy connection! • toRefs(state): Converts every property into an independent ref that stays linked to the source object.
Transitions: `<Transition>` and `<TransitionGroup>`.
Applies automated CSS enter/leave animation classes: Classes applied automatically: v-enter-from, v-enter-active, v-enter-to, v-leave-from, v-leave-active, v-leave-to • TransitionGroup: Handles lists with smooth positional layout transitions via FLIP animations (v-move).
Async Components (`defineAsyncComponent`).
Lazy-loads components on-demand using dynamic imports.
Vue Router 4 Composition API Integration.
```typescript import { useRouter, useRoute } from 'vue-router'; const router = useRouter(); // Programmatic navigation const route = useRoute(); // Reactive params and query function handleSearch() { router.push({ path: '/search', query: { q: 'vue' } }); }.
Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)
26 QuestionsDeep Dive into Vue 3 Reactivity Internals: `track()`, `trigger()`, and `TargetMap`.
Under the hood, Vue's reactivity engine uses a global WeakMap.
Vue 3 Compiler Optimizations: Block Tree and Patch Flags.
Unlike React (which diffs the entire Virtual DOM tree blindly), Vue 3 analyzes templates at compile-time: Patch Flags: The compiler tags dynamic bindings with binary bitmasks.
Custom Renderers: The `createRenderer` API.
Vue 3 separates the core runtime from the browser DOM: You can create custom renderers targeting Canvas, WebGL (TresJS), Terminal CLI (Ink-like), or Native Mobile by implementing standard node ops.
Managing Enterprise Pinia Stores: Plugins and SSR Hydration.
Pinia Plugins: Global interceptors for state persistence (localStorage) or telemetry.
Memory Leak Prevention in Long-Running Vue 3 SPAs.
Unregistered Listeners: Always remove window event listeners in onUnmounted • Third-Party Libraries: Explicitly call .destroy() on Chart.js, TinyMCE, or Leaflet map instances in onUnmounted • Uncleared Watchers: Watchers created outside of component setup() must be stopped manually by calling the returned unwatch function.
Error Handling in Vue 3: `onErrorCaptured` and Global Handlers.
onErrorCaptured: Component-level error boundary • Global Handler.
Performance Benchmarks: Vue 3 vs. Svelte 5 vs. React 19.
Vue 3: Hybrid model • Svelte 5: No Virtual DOM • React 19: Full VDOM diffing with Fiber concurrency.
Testing Vue 3 Components with Vitest and `@vue/test-utils`.
Testing Vue 3 components with Vitest and @vue/test-utils mounts the component in a virtual DOM, provides mock props, dispatches user interaction events, and asserts reactive DOM mutations. #### Code Example.
TypeScript Generics in `<script setup lang="ts">`.
Generic components (e.g. a reusable ``).
Microfrontends with Vue 3.
Package Vue 3 components as standard Web Components using defineCustomElement().
The 10 Principles of High-Performance Enterprise Vue 3 Architecture.
Standardize on `` and Composition API • Use shallowRef for large read-only datasets • Leverage v-memo in long list renders • Prefer Pinia Setup Stores over Options Stores.
Vue 3 `toRef` vs `toRefs` vs `toValue`: Deep Dive into Reactivity Utilities.
toRef: Creates a ref tracking a single property from a reactive object or converts a getter/value into a ref • toRefs: Converts all properties of a reactive object into individual refs, preserving reactivity when destructuring.
Custom Directives in Vue 3: Lifecycle Hooks and Practical Implementations.
Custom Directives allow direct low-level DOM manipulations on elements. In Vue 3, directive hooks mirror component lifecycles (created, beforeMount, mounted, beforeUpdate, updated, beforeUnmount, unmounted).
Vue 3 Reactivity Caveats: Loss of Reactivity During Destructuring and How to Preserve It.
Destructuring properties from a reactive() object strips their reactive link because JavaScript passes primitive values (number, string, boolean) by value, not by reference.: The Problem: Destructuring const { count } = reactive({ count: 0 }) creates an isolated primitive local variable that never updates when the.
`v-model` Modifiers in Vue 3: Built-in vs Custom Modifier Implementation.
v-model modifiers adjust how user input is bound to component state.: Built-in Modifiers.lazy (syncs on change event instead of input).number (typecasts input string to number via parseFloat).trim (strips • Custom Modifiers: Accessed via defineProps() in child components.
Vue 3 `defineModel` Macro (Vue 3.4+): Two-Way State Binding.
defineModel eliminates boilerplate prop/emit pairings for v-model. Previously, two-way binding required declaring defineProps(['modelValue']) and defineEmits(['update:modelValue']). With defineModel, the compiler automatically handles the prop declaration and event emission as a synchronous ref.
Vue 3 Slots Deep Dive: Default, Named, Scoped Slots, and Dynamic Slot Names.
Default Slot: Injects content without a name (`) • Named Slots: Target specific outlets () using • Scoped Slots: Pass data from child up to parent template (`), allowing parents to customize render logic while children control data loops.
`provide` / `inject` vs Pinia: Patterns for Hierarchical Component Trees.
provide / inject: Dependency injection across parent-to-deep-child ancestor trees • Pinia: Global application state with devtools time-travel, plugins, actions, and cross-route persistence.
Vue 3 Error Handling Architecture: `onErrorCaptured` vs `app.config.errorHandler`.
onErrorCaptured: Component-level hook that intercepts errors bubbling up from descendant components • app.config.errorHandler: Global catch-all handler for reporting unhandled errors to observability systems (Sentry, Datadog).
Dynamic and Async Components in Vue 3: `<component :is="...">` and `defineAsyncComponent`.
Dynamic Components (``): Dynamically swaps active components based on reactive state or tabs • Async Components (defineAsyncComponent): Splits large components into separate lazy bundles loaded on demand, with built-in loading and error.
Vue 3 `<Teleport>`: Escaping Stacking Contexts for Modals and Popovers.
Teleport renders a component's template DOM node into a different part of the document body (e.g. to="body" or to="#modal-target") while preserving Vue component reactivity, props, and emit hierarchies.
Vue 3 `<Transition>` and `<TransitionGroup>`: Classes, Hooks, and FLIP Animations.
Transition: Applies CSS enter/leave transition classes (v-enter-from, v-enter-active, v-enter-to, v-leave-from, v-leave-active, v-leave-to) to • TransitionGroup: Animates lists of items when elements are inserted, removed, or reordered using FLIP (First, Last, Invert, Play) algorithms.
Vue 3 Compiler Internals: Block Trees, Patch Flags, Static Hoisting, and Cache Handlers.
Vue 3's compiler optimizes virtual DOM reconciliation through ahead-of-time (AOT) template analysis: Patch Flags: Numbers embedded in VNodes telling the runtime exactly what needs updating (e.g. 1 for text, 2 for class, 8 for dynamic props).
Vue 3 Render Functions & JSX: When to Drop Down from Templates.
Render functions use the h() function to programmatically create Virtual DOM nodes (VNodes). While templates are declarative and optimized, render functions provide full JavaScript flexibility for highly dynamic scenarios (e.g. dynamic heading tags h(props.tag, slots.default()) or building form schema...
State Persistence and Plugins in Pinia.
Pinia plugins extend stores with cross-cutting concerns like persistence, logging, and error tracking. The $subscribe API listens for mutations and saves state to localStorage or sessionStorage.
Vue 3 Memory Leaks: Common Pitfalls and Profiling Techniques.
Vue 3 automates most memory management, but common developer oversights cause detached DOM trees and memory bloat: Uncleaned Window / Document Listeners: Adding window.addEventListener('resize', fn) without removing it in onUnmounted • Lingering Timers: setInterval continuing to run after component teardown.