LearnThatStack Ace your next interview

Vue.js

Vue 3.5+ with script setup, Pinia and Vue Router Checked Oct 2026 109 code snippets

The model

  • Vue's reactivity tracks which state each component reads while it renders. When that state changes, Vue re-renders only those components, so you never touch the DOM by hand.
  • ref() holds any value. Script reads it through .value, and the template unwraps it. reactive() turns an object into a Proxy, and destructuring it loses reactivity.
  • Vue batches changes. The DOM updates on the next tick, once per component, so code that reads the new DOM waits for nextTick().
  • Data flows down as props and up as events. A child never changes a prop. It emits an event, and the parent changes the value.
  • New code uses the Composition API in <script setup>. The Options API, with data, methods and this, still works and still comes up in interviews.
Your codehandlers, setupReactive stateref, reactiveRender effectcomponent renderDOMbrowser nodesRENDERreads track()mountWRITEcount.value++trigger() queuedTICKpatch changesnextTick() resolves
A render reads state, so Vue tracks it. A write queues that render, and on the next tick Vue patches only the DOM nodes that changed.

App setup & SFCs

what Vue is, and how an app is put together

Vue next to React and Angular

Write the UIHTML templates by default, JSX optional
Update only what changedVue tracks reads. React re-runs components.
Compare what comes built inOfficial router and store, unlike React. Lighter than Angular.

Templates & directives

bind data, branch, loop and handle input

Reactivity & watchers

state Vue tracks, and code that reacts to it

ref, reactive and shallowRef

Hold any reactive valueconst n = ref(0)Read n.value in script
Make an object reactivereactive({ a: 1 })Objects only, no .value
Hold big data you replace wholeshallowRef(rows)Nested edits need triggerRef()
Force a re-render$forceUpdate()A sign of a reactivity bug

TrapReplacing or destructuring a reactive() object breaks reactivity. That's why Vue recommends ref() by default.

Props, events & slots

pass data down, send changes up, take content in

Lifecycle & composables

run code at set points, then reuse the logic

Lifecycle hooks

List the hooks in orderCreate, mount, update, unmount, each with a before hook
Run code before mountIn setup code, or created
Touch the DOMonMounted(fn)Browser only, not in SSR
Name Vue 2's removal hookbeforeDestroyNow beforeUnmount

TrapRegister hooks synchronously in setup. A hook inside a setTimeout has no component to attach to.

Fetch data and catch errors

Refetch when a prop changeswatch(() => p.id, load)With immediate: true
Abort old fetch (3.5+)onWatcherCleanup(fn)
Show a fallback during async setup<Suspense>Still experimental
Catch errors in a subtree, or app-wideonErrorCaptured(fn)app.config.errorHandler

TrapVue never sees an error in your own setTimeout or an unawaited promise. Catch those yourself.

Shared state & Pinia

share data beyond one parent and child

Vue Router

map URLs to components

Built-in components

switch, cache, move and animate components

Dynamic components, KeepAlive, Teleport

Switch components<component :is="tab">
Keep a hidden component's state<KeepAlive>onActivated() runs each time it shows
Render a modal under body<Teleport to="body">Escapes a parent's transform

TrapWithout max, KeepAlive caches every instance it sees, which can leak memory.

Transitions

fromactivetransitiontoend stateeventsinsertendstime

On insert, Vue adds v-enter-from and v-enter-active. A frame later it swaps v-enter-from for v-enter-to. Both go when the transition ends.

Animate an element in and out<Transition name="fade">
Animate a list<TransitionGroup>.list-move slides moved items

TrapEvery child of <TransitionGroup> needs a unique key, and it has no mode.

Performance & rendering

render less, and ship less code

Tests, SSR & migration

test components, render on the server, leave Vue 2

Server rendering and hydration

Render the app to HTMLrenderToString(app)createSSRApp() hydrates it
Keep users' state apartA new app, router and store per request
Render a browser-only partGate it on a flag set in onMounted()
Generate matching IDs (3.5+)useId()
Get SSR without the setupNuxt. File-based routes, auto-imports, SSR on by default.

TrapRandom values, time zones and a <div> inside a <p> cause hydration mismatches.

Vue 2 to Vue 3

Create an app the Vue 2 waynew Vue({ render })Vue 3 uses createApp()
Replace a Vue 2 filterUse a method or a computed
Migrate one warning at a time@vue/compatWarns on each Vue 2 API

TipVue 2 reached end of life on December 31, 2023.

TrapThe migration build can't run libraries that rely on Vue 2 internals. Check each one has a Vue 3 version.

Found this useful? Pass it on.
Pro · $10/mo

This sheet stays free. With Pro, you can:

  • Every answer on this sheet. Read the full answer to all 105 questions it links, not just the 15 free ones.
  • My sheet. The cards you star and the ones you miss in Quiz me, from every sheet, on one page to quiz and print.
  • PDFs. Download this sheet and My sheet, laid out for A4, with every question a link to its answer.
  • The rest of Pro. Every answer in the question library, and 1,000 AI credits a month.