Vue Js

Vue Js

Top Interview Questions

About Vue Js

What is Vue.js?

Vue.js (commonly called “Vue”) is an open-source JavaScript framework used for building user interfaces (UIs) and single-page applications (SPAs). Created by Evan You in 2014, Vue has grown into one of the most popular frontend frameworks alongside React and Angular. It is known for its simplicity, flexibility, and performance.

At its core, Vue.js focuses on the view layer of an application—the part users interact with—while also offering tools and libraries to handle complex application logic when needed.


Key Features of Vue.js

1. Reactive Data Binding

One of Vue’s standout features is its reactivity system. When data changes, the UI automatically updates without manual DOM manipulation. This is based on the concept of a reactive data model, where Vue tracks dependencies and updates only the necessary parts of the interface.

For example:

const app = Vue.createApp({
  data() {
    return {
      message: "Hello Vue!"
    }
  }
})

If message changes, Vue updates the UI instantly.


2. Component-Based Architecture

Vue applications are built using components, which are reusable and self-contained pieces of code. Each component typically includes:

  • Template (HTML structure)

  • Script (logic)

  • Style (CSS)

This modular approach makes applications easier to maintain and scale.


3. Declarative Rendering

Vue uses a declarative syntax, meaning you describe what the UI should look like based on the data, and Vue handles how to update it.

Example:

<div>{{ message }}</div>

4. Directives

Vue provides special attributes called directives that extend HTML functionality. Common ones include:

  • v-bind → Bind attributes

  • v-model → Two-way data binding

  • v-if → Conditional rendering

  • v-for → Loop through data

Example:

<input v-model="message">

5. Virtual DOM

Like React, Vue uses a Virtual DOM, which is a lightweight representation of the real DOM. Changes are computed efficiently and applied only where necessary, improving performance.


6. Ease of Integration

Vue is often described as a progressive framework, meaning you can:

  • Use it for a small part of a webpage, or

  • Build full-scale applications

It integrates easily with existing projects, unlike some frameworks that require a full rewrite.


Vue Ecosystem

Vue is not just a framework—it comes with a rich ecosystem of supporting tools:

Vue Router

Handles navigation between different views/pages in a single-page application.

Vuex / Pinia

State management libraries for managing shared data across components. Pinia is now the modern recommendation.

Vue CLI & Vite

Tools for setting up and building Vue projects quickly. Vite is especially popular for its speed.


Vue Versions

Vue has evolved over time, with major versions including:

  • Vue 2: Widely used, stable, and beginner-friendly

  • Vue 3: Modern version with improved performance and features like:

    • Composition API

    • Better TypeScript support

    • Smaller bundle size

Vue 3 is now the recommended version for new projects.


Composition API vs Options API

Vue offers two ways to write components:

Options API (Classic)

export default {
  data() {
    return { count: 0 }
  },
  methods: {
    increment() {
      this.count++
    }
  }
}

Composition API (Modern)

import { ref } from 'vue'

export default {
  setup() {
    const count = ref(0)
    const increment = () => count.value++

    return { count, increment }
  }
}

The Composition API is more flexible and better suited for large applications.


Advantages of Vue.js

1. Beginner-Friendly

Vue is easy to learn compared to other frameworks. Its syntax is simple, and developers can start with basic HTML, CSS, and JavaScript knowledge.

2. Lightweight

Vue has a small bundle size, which helps in faster load times.

3. Flexibility

You can use Vue for:

  • Small widgets

  • Medium applications

  • Large enterprise-level systems

4. Strong Community

Vue has a large and active community, with plenty of tutorials, plugins, and support.

5. Excellent Documentation

Vue’s official documentation is widely regarded as one of the best in the frontend ecosystem.


Disadvantages of Vue.js

1. Smaller Ecosystem (Compared to React)

Although growing, Vue’s ecosystem is still smaller than React’s in terms of third-party libraries.

2. Over-Flexibility

Vue allows multiple ways to do the same thing, which can lead to inconsistency in large teams.

3. Job Market

In some regions, demand for Vue developers may be lower compared to React or Angular.


Vue vs React vs Angular

Feature Vue.js React Angular
Learning Curve Easy Medium Hard
Flexibility High High Low
Size Small Medium Large
Backing Independent Meta Google
  • Vue is best for simplicity and rapid development

  • React is best for flexibility and ecosystem

  • Angular is best for enterprise-level structure


Use Cases of Vue.js

Vue is used in a wide range of applications:

1. Single Page Applications (SPAs)

Apps that load once and dynamically update content without refreshing.

2. Dashboards

Admin panels and analytics dashboards benefit from Vue’s reactive UI.

3. E-commerce Websites

Vue is often used to build fast, interactive shopping experiences.

4. Progressive Web Apps (PWAs)

Vue supports building apps that work offline and behave like native apps.


Companies Using Vue.js

Many well-known companies use Vue in production:

  • Alibaba

  • Xiaomi

  • GitLab

  • Adobe


Simple Example of a Vue App

Here’s a minimal Vue example:

<div id="app">
  <p>{{ message }}</p>
  <button @click="reverseMessage">Reverse</button>
</div>

<script>
Vue.createApp({
  data() {
    return {
      message: "Hello Vue!"
    }
  },
  methods: {
    reverseMessage() {
      this.message = this.message.split('').reverse().join('')
    }
  }
}).mount('#app')
</script>

This app displays a message and reverses it when the button is clicked.


Why Choose Vue.js?

You might choose Vue if you want:

  • A simple and clean framework

  • Fast development with minimal setup

  • Flexibility to scale your application

  • A balance between power and ease of use

Vue is especially ideal for beginners and small teams, but it is also powerful enough for large-scale applications.


Conclusion

Vue.js is a modern, progressive JavaScript framework that strikes a balance between simplicity and capability. With features like reactive data binding, component-based architecture, and a strong ecosystem, it enables developers to build fast and maintainable web applications.

Whether you’re just starting out in frontend development or building a complex application, Vue provides a smooth and efficient development experience.

Fresher Interview Questions

 

1. What is Vue.js?

Answer:
Vue.js is a progressive JavaScript framework used for building user interfaces, especially single-page applications (SPAs).

  • It focuses on the view layer only

  • Easy to integrate with other libraries or existing projects

  • Uses a component-based architecture


2. What are the key features of Vue.js?

Answer:
Some important features:

  • Reactive Data Binding – UI updates automatically when data changes

  • Component-Based Architecture

  • Virtual DOM

  • Directives (v-if, v-for, etc.)

  • Computed Properties & Watchers

  • Lightweight & easy to learn


3. What is the Vue Instance?

Answer:
A Vue instance is the root object that controls a Vue app.

Example:

const app = Vue.createApp({
  data() {
    return {
      message: "Hello Vue!"
    }
  }
});
  • It connects data + template + methods

  • Every Vue app starts with creating an instance


4. What is data binding in Vue?

Answer:
Data binding means synchronizing data between the model and the view.

Types:

  • One-way binding{{ message }}

  • Two-way bindingv-model

Example:

<input v-model="name">
<p>{{ name }}</p>

5. What are directives in Vue?

Answer:
Directives are special attributes with v- prefix that control DOM behavior.

Common directives:

  • v-bind → bind attributes

  • v-model → two-way binding

  • v-if → conditional rendering

  • v-for → looping

  • v-on → event handling

Example:

<p v-if="isVisible">Hello</p>

6. Difference between v-if and v-show?

Answer:

Feature v-if v-show
Rendering Adds/removes element Toggles visibility
Performance Slower (DOM creation) Faster
Use case Conditional rarely changes Frequent toggling

7. What is a component in Vue?

Answer:
A component is a reusable piece of UI with its own logic and template.

Example:

app.component('my-component', {
  template: `<h1>Hello Component</h1>`
});
  • Helps in code reusability

  • Makes app modular


8. What is the difference between props and data?

Answer:

Props Data
Passed from parent Local state
Read-only Mutable
Used for communication Used for internal logic

9. What are computed properties?

Answer:
Computed properties are cached values that depend on reactive data.

Example:

computed: {
  fullName() {
    return this.firstName + " " + this.lastName;
  }
}
  • Only recalculates when dependencies change

  • Better performance than methods


10. What are watchers in Vue?

Answer:
Watchers observe changes and execute code.

Example:

watch: {
  count(newVal, oldVal) {
    console.log("Changed:", newVal);
  }
}
  • Used for async operations or API calls


11. What is the Vue lifecycle?

Answer:
Vue instance goes through several stages:

  • created → data initialized

  • mounted → DOM ready

  • updated → data changes

  • unmounted → destroyed

Example:

mounted() {
  console.log("Component mounted");
}

12. What is Vue CLI?

Answer:
Vue CLI is a tool to create and manage Vue projects.

Command:

npm install -g @vue/cli
vue create my-project

13. What is Vue Router?

Answer:
Vue Router is used for navigation between pages in SPA.

Features:

  • Dynamic routing

  • Nested routes

  • Route guards


14. What is Vuex?

Answer:
Vuex is a state management library for Vue apps.

Used when:

  • Many components share data

Core concepts:

  • State

  • Mutations

  • Actions

  • Getters


15. What is v-bind?

Answer:
Used to bind HTML attributes dynamically.

Example:

<img v-bind:src="imageURL">

Shortcut:

<img :src="imageURL">

16. What is v-model?

Answer:
Creates two-way binding between input and data.

Example:

<input v-model="username">

17. What is event handling in Vue?

Answer:
Using v-on directive.

Example:

<button v-on:click="handleClick">Click</button>

Shortcut:

<button @click="handleClick">

18. What is a Single File Component (SFC)?

Answer:
A .vue file that contains:

<template></template>
<script></script>
<style></style>

Benefits:

  • Better organization

  • Scoped styles


19. What is the Virtual DOM?

Answer:
A lightweight copy of real DOM.

  • Vue updates only changed parts

  • Improves performance


20. Why use Vue over other frameworks?

Answer:

  • Easy to learn

  • Lightweight

  • Flexible

  • Great documentation

  • Faster development


 

21. What is the difference between methods and computed properties?

Answer:

Feature Methods Computed
Execution Runs every time called Cached
Performance Less efficient More efficient
Use case Actions/events Derived values

Example:

data() {
  return {
    firstName: "John",
    lastName: "Doe"
  }
},
methods: {
  fullNameMethod() {
    return this.firstName + " " + this.lastName;
  }
},
computed: {
  fullNameComputed() {
    return this.firstName + " " + this.lastName;
  }
}

πŸ‘‰ Key Point:
Computed is preferred when the result depends on reactive data.


22. What is the difference between watch and computed?

Answer:

Computed Watch
Returns value Performs side effects
Cached Not cached
Used in templates Used for async or complex logic

Example (watch):

watch: {
  search(query) {
    this.fetchResults(query);
  }
}

πŸ‘‰ Use watch when:

  • Calling APIs

  • Performing async tasks


23. What are Vue lifecycle hooks in detail?

Answer:

Lifecycle hooks allow you to run code at specific stages.

Important Hooks:

  1. created()

    • Data initialized

    • API calls can be made

  2. mounted()

    • DOM available

    • Good for DOM manipulation

  3. updated()

    • Runs after data change

  4. unmounted()

    • Cleanup (timers, listeners)

Example:

mounted() {
  console.log("DOM is ready");
}

24. What is the difference between created() and mounted()?

Answer:

created() mounted()
No DOM access DOM available
Faster Slightly slower
Used for API calls Used for DOM manipulation

25. What is a key attribute in Vue?

Answer:
The key attribute helps Vue identify elements uniquely when rendering lists.

Example:

<li v-for="item in items" :key="item.id">
  {{ item.name }}
</li>

πŸ‘‰ Prevents bugs and improves performance.


26. What is conditional rendering?

Answer:
Showing/hiding elements based on conditions.

Directives:

  • v-if

  • v-else

  • v-show

Example:

<p v-if="isLoggedIn">Welcome</p>
<p v-else>Please login</p>

27. What is list rendering in Vue?

Answer:
Rendering multiple elements using v-for.

Example:

<ul>
  <li v-for="user in users" :key="user.id">
    {{ user.name }}
  </li>
</ul>

πŸ‘‰ Can loop through:

  • Arrays

  • Objects

  • Numbers


28. What is event modifier in Vue?

Answer:
Modifiers simplify event handling.

Examples:

<form @submit.prevent="submitForm">
<button @click.stop="handleClick">

Common modifiers:

  • .prevent → prevent default

  • .stop → stop propagation

  • .once → run once


29. What are form input bindings?

Answer:
Using v-model with different inputs.

Examples:

<input v-model="text">
<input type="checkbox" v-model="checked">
<select v-model="selected">

πŸ‘‰ Vue automatically handles value syncing.


30. What are dynamic components?

Answer:
Switching components dynamically.

Example:

<component :is="currentComponent"></component>
data() {
  return {
    currentComponent: "HomeComponent"
  }
}

31. What is slot in Vue?

Answer:
Slots allow content distribution in components.

Basic slot:

<slot></slot>

Usage:

<MyComponent>
  <p>Hello Slot</p>
</MyComponent>

32. What are named slots?

Answer:
Multiple slots with names.

<slot name="header"></slot>
<slot name="footer"></slot>

Usage:

<template v-slot:header>
  Header Content
</template>

33. What is props validation?

Answer:
Ensures props are passed correctly.

props: {
  age: {
    type: Number,
    required: true,
    default: 18
  }
}

34. What is emit in Vue?

Answer:
Used to send data from child to parent.

this.$emit('update', data);

Parent:

<Child @update="handleUpdate" />

35. What is two-way communication in Vue?

Answer:

  • Parent → Child → via props

  • Child → Parent → via emit


36. What is provide/inject?

Answer:
Used to share data across deeply nested components.

provide() {
  return {
    message: "Hello"
  }
}
inject: ['message']

37. What is mixin in Vue?

Answer:
Reusable logic across components.

const myMixin = {
  created() {
    console.log("Mixin called");
  }
}

38. What is Composition API?

Answer:
A modern way to write Vue logic (Vue 3).

import { ref } from 'vue';

setup() {
  const count = ref(0);
  return { count };
}

πŸ‘‰ Better for:

  • Large apps

  • Code reuse


39. What is ref in Vue?

Answer:
Creates reactive variables.

const count = ref(0);

Access:

count.value

40. What is reactive() in Vue?

Answer:
Used for objects.

import { reactive } from 'vue';

const state = reactive({
  name: "John"
});

🎯 Extra Important Viva Questions

41. What is SPA (Single Page Application)?

A web app that loads a single HTML page and updates dynamically without reload.


42. What is the difference between Vue 2 and Vue 3?

Vue 2 Vue 3
Options API Composition API
Slower Faster
Limited TS support Better TypeScript

43. What is lazy loading?

Loading components only when needed.


44. What is debouncing in Vue?

Delaying function execution (e.g., search input).


🧠 Pro Interview Tip

Interviewers often ask:
πŸ‘‰ “Explain with example”
πŸ‘‰ “Where did you use this?”

So prepare:

  • Todo app

  • API fetch example

  • Form validation

 

🎯 Bonus Tips for Freshers

  • Be ready to write small code snippets

  • Understand basic JavaScript concepts

  • Practice mini projects (Todo app, Counter app)

  • Know difference between:

    • methods vs computed

    • props vs state

    • v-if vs v-show


 

Experienced Interview Questions

 

πŸ”Ή 1. What are the key differences between Vue 2 and Vue 3?

βœ… Answer:

Vue 3 introduced major improvements:

1. Composition API

  • Vue 2: Options API (data, methods, computed)

  • Vue 3: Composition API (setup())

import { ref } from 'vue'

export default {
  setup() {
    const count = ref(0)
    return { count }
  }
}

πŸ‘‰ Benefits:

  • Better logic reuse

  • Cleaner large components

  • TypeScript friendly


2. Reactivity System (Proxy-based)

  • Vue 2: Object.defineProperty

  • Vue 3: Proxy

πŸ‘‰ Advantages:

  • Detects property addition/deletion

  • Better performance

  • No need for Vue.set()


3. Performance Improvements

  • Faster rendering using Virtual DOM optimizations

  • Tree-shaking support → smaller bundles


4. New Features

  • Fragments (multiple root elements)

  • Teleport

  • Suspense


πŸ”Ή 2. Explain Composition API vs Options API

βœ… Answer:

Options API

export default {
  data() {
    return { count: 0 }
  },
  methods: {
    increment() {
      this.count++
    }
  }
}

Composition API

import { ref } from 'vue'

export default {
  setup() {
    const count = ref(0)
    const increment = () => count.value++
    return { count, increment }
  }
}

πŸ” Key Differences:

Feature Options API Composition API
Code organization Feature-based Logic-based
Reusability Mixins Composables
TypeScript support Limited Excellent

πŸ‘‰ For 4+ years: Composition API is preferred


πŸ”Ή 3. What is reactivity in Vue 3?

βœ… Answer:

Reactivity means Vue automatically updates the UI when data changes.

Core APIs:

  • ref() → for primitives

  • reactive() → for objects

const count = ref(0)
const state = reactive({ name: 'John' })

How it works:

  • Vue uses Proxy to track:

    • getters → dependency tracking

    • setters → trigger updates


πŸ”Ή 4. What are refs vs reactive?

βœ… Answer:

Feature ref() reactive()
Data type Primitive & object Object only
Access .value Direct
Use case Simple values Complex objects
const age = ref(25)
const user = reactive({ name: 'Sam' })

πŸ‘‰ Best practice:

  • Use ref for primitives

  • Use reactive for structured state


πŸ”Ή 5. What are composables?

βœ… Answer:

Reusable functions using Composition API.

// useCounter.js
import { ref } from 'vue'

export function useCounter() {
  const count = ref(0)
  const increment = () => count.value++
  return { count, increment }
}

Usage:

const { count, increment } = useCounter()

πŸ‘‰ Similar to React hooks
πŸ‘‰ Replaces mixins


πŸ”Ή 6. Explain Vue lifecycle hooks (Composition API)

βœ… Answer:

Hook Purpose
onMounted After DOM render
onUpdated After update
onUnmounted Cleanup
import { onMounted } from 'vue'

onMounted(() => {
  console.log('Mounted')
})

πŸ”Ή 7. What is Teleport?

βœ… Answer:

Allows rendering components outside the DOM hierarchy.

<teleport to="#modal">
  <div>Modal Content</div>
</teleport>

πŸ‘‰ Use case:

  • Modals

  • Tooltips

  • Popups


πŸ”Ή 8. What is Suspense?

βœ… Answer:

Handles async components gracefully.

<Suspense>
  <template #default>
    <AsyncComponent />
  </template>
  <template #fallback>
    Loading...
  </template>
</Suspense>

πŸ‘‰ Useful for:

  • API calls

  • Lazy loading components


πŸ”Ή 9. How does Vue handle state management?

βœ… Answer:

Options:

  1. Local state (ref/reactive)

  2. Global state using Pinia (recommended)

import { defineStore } from 'pinia'

export const useStore = defineStore('main', {
  state: () => ({ count: 0 })
})

πŸ‘‰ Why Pinia:

  • Lightweight

  • Type-safe

  • Vue 3 official


πŸ”Ή 10. What is watch vs watchEffect?

βœ… Answer:

watch

  • Tracks specific dependency

watch(count, (newVal) => {
  console.log(newVal)
})

watchEffect

  • Automatically tracks dependencies

watchEffect(() => {
  console.log(count.value)
})

πŸ‘‰ Difference:

  • watch → explicit

  • watchEffect → automatic


πŸ”Ή 11. How do you optimize Vue performance?

βœ… Answer:

Techniques:

  • Lazy loading routes

  • Code splitting

  • v-once

  • v-memo

  • Use computed instead of methods

  • Avoid unnecessary watchers

<div v-once>{{ staticContent }}</div>

πŸ”Ή 12. What is Virtual DOM in Vue?

βœ… Answer:

  • Lightweight JS representation of real DOM

  • Vue compares old vs new (diffing)

  • Updates only changed parts

πŸ‘‰ Benefits:

  • Efficient rendering

  • Better performance


πŸ”Ή 13. What are directives in Vue?

βœ… Answer:

Examples:

  • v-if

  • v-for

  • v-model

  • v-bind

  • v-on

Custom directive:

app.directive('focus', {
  mounted(el) {
    el.focus()
  }
})

πŸ”Ή 14. How does Vue routing work?

βœ… Answer:

Using Vue Router:

import { createRouter, createWebHistory } from 'vue-router'

Features:

  • Dynamic routing

  • Lazy loading

  • Navigation guards


πŸ”Ή 15. What are navigation guards?

βœ… Answer:

router.beforeEach((to, from, next) => {
  if (!isAuthenticated) next('/login')
  else next()
})

πŸ‘‰ Use cases:

  • Authentication

  • Authorization

  • Logging


πŸ”Ή 16. Explain slots in Vue

βœ… Answer:

Default slot

<slot></slot>

Named slot

<slot name="header"></slot>

Usage:

<template v-slot:header>
  Header Content
</template>

πŸ”Ή 17. What is emit in Vue?

βœ… Answer:

Child → Parent communication

emit('update', value)

Parent:

<Child @update="handler" />

πŸ”Ή 18. How do you handle forms in Vue?

βœ… Answer:

<input v-model="name" />

Modifiers:

  • .lazy

  • .trim

  • .number


πŸ”Ή 19. What is nextTick?

βœ… Answer:

Wait for DOM update

import { nextTick } from 'vue'

await nextTick()

πŸ‘‰ Use when:

  • Need updated DOM after state change


πŸ”Ή 20. How do you structure large Vue apps?

βœ… Answer:

Best practices:

  • Feature-based folders

  • Use composables

  • Centralized API services

  • Pinia for state

  • Separate UI & business logic

Example:

/components
/composables
/views
/store
/services
/router

πŸ”Ή 21. How does Vue 3’s reactivity system work internally?

βœ… Answer:

Vue 3 uses Proxy-based reactivity.

Core idea:

  • Wrap objects using Proxy

  • Intercept:

    • get → track dependency

    • set → trigger updates

Internally:

function reactive(target) {
  return new Proxy(target, {
    get(obj, key) {
      track(obj, key)
      return obj[key]
    },
    set(obj, key, value) {
      obj[key] = value
      trigger(obj, key)
      return true
    }
  })
}

Key Concepts:

  • Dependency tracking (via track)

  • Effect triggering (via trigger)

  • Uses WeakMap → Map → Set structure

πŸ‘‰ Why it matters:

  • Helps debug performance issues

  • Helps understand watcher behavior


πŸ”Ή 22. What is shallowRef vs ref?

βœ… Answer:

ref

  • Deep reactive

  • Tracks nested changes

const state = ref({ count: 0 })
state.value.count++ // triggers update

shallowRef

  • Only tracks .value

  • Ignores nested changes

const state = shallowRef({ count: 0 })
state.value.count++ // ❌ no re-render

πŸ‘‰ Use cases:

  • Large objects (performance optimization)

  • External libraries (e.g., charts)


πŸ”Ή 23. What is markRaw and when to use it?

βœ… Answer:

Prevents Vue from making an object reactive.

import { markRaw } from 'vue'

const obj = markRaw({ name: 'test' })

πŸ‘‰ Use cases:

  • Third-party libraries (e.g., Mapbox, Chart.js)

  • Performance optimization


πŸ”Ή 24. What is the difference between computed and watch?

βœ… Answer:

Feature computed watch
Purpose Derived state Side effects
Caching Yes No
Sync/Async Sync Async

Example:

const fullName = computed(() => first.value + last.value)
watch(fullName, (val) => {
  console.log(val)
})

πŸ‘‰ Rule:

  • Use computed for values

  • Use watch for side effects (API calls)


πŸ”Ή 25. How do you handle API calls in Vue (best practice)?

βœ… Answer:

❌ Avoid:

  • Direct API calls in components


βœ… Use Service Layer + Composable

// api/userService.js
export const fetchUsers = () => fetch('/api/users')
// composables/useUsers.js
import { ref, onMounted } from 'vue'
import { fetchUsers } from '../api/userService'

export function useUsers() {
  const users = ref([])

  onMounted(async () => {
    users.value = await fetchUsers()
  })

  return { users }
}

πŸ‘‰ Benefits:

  • Clean architecture

  • Reusable logic

  • Testable


πŸ”Ή 26. What are memory leaks in Vue and how do you prevent them?

βœ… Answer:

Causes:

  • Unremoved event listeners

  • Unstopped watchers

  • Third-party libraries


Fix:

import { onUnmounted } from 'vue'

onUnmounted(() => {
  window.removeEventListener('resize', handler)
})

πŸ‘‰ Also:

  • Use watchEffect cleanup

  • Avoid global references


πŸ”Ή 27. What is dynamic component rendering?

βœ… Answer:

<component :is="currentComponent" />
const currentComponent = ref('Home')

πŸ‘‰ Use cases:

  • Tabs

  • Feature toggles

  • CMS-driven UI


πŸ”Ή 28. What are async components?

βœ… Answer:

Lazy-loaded components:

const AsyncComp = defineAsyncComponent(() =>
  import('./MyComponent.vue')
)

πŸ‘‰ Benefits:

  • Smaller bundle size

  • Faster initial load


πŸ”Ή 29. How does Vue handle large lists efficiently?

βœ… Answer:

Techniques:

  1. Key usage

<div v-for="item in list" :key="item.id">
  1. Virtual scrolling

  • Use libraries like:

    • Vue Virtual Scroller

  1. Pagination

  2. v-memo

<div v-memo="[item.id]">

πŸ”Ή 30. What is SSR in Vue?

βœ… Answer:

SSR = Server-Side Rendering

Flow:

  1. Render HTML on server

  2. Send to client

  3. Hydrate with Vue


Tools:

  • Nuxt.js


Benefits:

  • SEO friendly

  • Faster first paint


Challenges:

  • Hydration mismatch

  • More complexity


πŸ”Ή 31. What is hydration?

βœ… Answer:

Process where Vue attaches event listeners to server-rendered HTML.

πŸ‘‰ Problem:

  • If server HTML ≠ client state → errors


πŸ”Ή 32. What are provide/inject?

βœ… Answer:

Used for deep component communication.

provide('theme', 'dark')
const theme = inject('theme')

πŸ‘‰ Alternative to prop drilling


πŸ”Ή 33. How do you implement authentication in Vue?

βœ… Answer:

Steps:

  1. Store token (localStorage/cookie)

  2. Use router guards

router.beforeEach((to, from, next) => {
  if (!token) next('/login')
  else next()
})
  1. Use Axios interceptors

πŸ‘‰ Best practice:

  • Use refresh tokens

  • Avoid storing sensitive data in localStorage


πŸ”Ή 34. How do you handle errors globally?

βœ… Answer:

app.config.errorHandler = (err) => {
  console.error(err)
}

πŸ‘‰ Also:

  • Use try/catch in async calls

  • Error boundaries (Vue 3 feature)


πŸ”Ή 35. What is a render function?

βœ… Answer:

Alternative to templates:

import { h } from 'vue'

export default {
  render() {
    return h('div', 'Hello')
  }
}

πŸ‘‰ Use cases:

  • Dynamic UI generation

  • Library development


πŸ”Ή 36. What is v-model under the hood?

βœ… Answer:

<input v-model="name" />

Equivalent to:

<input :value="name" @input="name = $event.target.value" />

πŸ”Ή 37. What is microfrontend architecture with Vue?

βœ… Answer:

Split app into smaller independent apps.

Tools:

  • Module Federation

  • Single-SPA

πŸ‘‰ Benefits:

  • Independent deployment

  • Team scalability


πŸ”Ή 38. How do you test Vue components?

βœ… Answer:

Tools:

  • Vue Test Utils

  • Jest / Vitest

import { mount } from '@vue/test-utils'

const wrapper = mount(Component)
expect(wrapper.text()).toContain('Hello')

πŸ”Ή 39. What is the difference between SPA and MPA?

βœ… Answer:

SPA MPA
Single page Multiple pages
Faster navigation Full reload
Uses Vue Router Traditional routing

πŸ”Ή 40. How do you design a scalable Vue project?

βœ… Answer:

Key principles:

  • Feature-based structure

  • Composables for logic

  • API abstraction

  • State centralization (Pinia)

  • Lazy loading


πŸ”₯ Real Interview Scenario Questions


πŸ”Ή Q41: How would you optimize a slow Vue app?

βœ… Answer:

  • Analyze with Vue DevTools

  • Reduce re-renders

  • Use computed instead of methods

  • Lazy load components

  • Optimize watchers

  • Use shallowRef


πŸ”Ή Q42: How would you handle a form with 100+ fields?

βœ… Answer:

  • Use dynamic form rendering

  • Split into smaller components

  • Use validation libraries (VeeValidate)

  • Debounce input


πŸ”Ή Q43: How would you share state across unrelated components?

βœ… Answer:

  • Pinia (best)

  • provide/inject (lightweight)

  • Event bus (not recommended)


βœ… Final Tip (Very Important)

For 4+ years experience, interviewers expect:

  • Why you chose a solution

  • Tradeoffs

  • Real examples from your projects