Tech Interview RoomStudy guides

Vue.js

What is Vue.js and how does a Single File Component work?

Beginner · 2 min read · Lesson 1 of 12 in Vue.js

Vue is a progressive JavaScript framework for building user interfaces. "Progressive" means you can drop it into one part of a page or build a full single-page app with routing, state and SSR (through Nuxt). Its core ideas are declarative templates and a reactivity system that updates the DOM automatically when data changes.

Single File Components (.vue)

One file holds the three parts of a component:

  • <script setup>: the logic, using the Composition API. Every top-level variable, function and import is available in the template.
  • <template>: HTML-based markup with directives (v-if, v-for, v-bind, v-on, v-model). The compiler turns it into an optimised render function.
  • <style scoped>: CSS that applies only to this component.

Tooling: Vite with create-vue for new projects, Vue DevTools, and the Vue - Official VS Code extension (Volar) for TypeScript support in templates.

Options API vs Composition API

The Options API (data, methods, computed, watch) groups code by option type; the Composition API (ref, computed, watch inside setup) groups code by feature and makes logic reusable through composables. Both are supported in Vue 3; new code usually uses <script setup>.

Example

vue
<script setup>
import { ref, computed } from 'vue';

const name = ref('Asha');
const clicks = ref(0);
const greeting = computed(() => `Hello, ${name.value}!`);

function increment() {
  clicks.value++;
}
</script>

<template>
  <h1>{{ greeting }}</h1>
  <input v-model="name" placeholder="Your name" />
  <button @click="increment">Clicked {{ clicks }} times</button>
</template>

<style scoped>
h1 { color: #42b883; }
</style>

In <script> a ref is read with .value; in the template it is unwrapped automatically.

Follow-up questions interviewers ask

Try answering each one before you open it.

How is Vue different from React at a high level?

Vue uses templates compiled to optimised render functions and fine-grained reactivity: it tracks exactly which component reads which value, so only those components re-render, without manual memoisation. React uses JSX and re-runs components top-down when state changes, relying on memoisation or the React Compiler to skip work. Vue also ships official routing (Vue Router) and state (Pinia); React leaves those to the ecosystem.