Vue Js Interview Questions

1. What is Vue.js?

Vue.js is a progressive JavaScript framework for building user interfaces and single-page applications. It uses a reactive data binding system and a component-based architecture.

2. What are the key features of Vue 3?

  • Composition API for better logic reuse
  • Improved TypeScript support
  • Smaller bundle size
  • Better performance
  • Teleport for DOM manipulation outside Vue root
  • Fragments (multiple root nodes in a component)
  • Security & Identity (Azure Active Directory)

3. What is the Composition API in Vue 3?

The Composition API allows developers to organize and reuse logic more flexibly by using functions like setup(), ref(), reactive(), and computed() instead of the Options API.

4. Explain the difference between ref() and reactive() in Vue 3.

  • ref() is used to create a reactive primitive value or an object with a .value property.
  • reactive() makes an entire object reactive and returns a reactive proxy.

5. How does Vue.js handle reactivity?

Vue uses a reactive system based on ES6 Proxies (in Vue 3) or Object.defineProperty (Vue 2) to track dependencies and trigger view updates when reactive data changes.

6. What are Vue directives?

Directives are special attributes with the v- prefix in Vue templates that apply reactive behavior to the DOM, such as v-if, v-for, v-model, v-bind, and v-on.

7. How does v-model work?

v-model creates two-way data binding on form inputs or custom components by syncing a value prop and an event (usually input or update:modelValue).

8. What is a Vue component?

A Vue component is a reusable and encapsulated block of UI with its own template, logic, and styles, allowing modular app structure.

9. What is the Vue Router?

Vue Router is the official router for Vue.js, enabling navigation between different components/pages with URL-based routing in single-page applications.

10. How do you communicate between components in Vue?

  • Parent to child: Props
  • Child to parent: Events with $emit()

11. What is Vuex?

Vuex is the official state management library for Vue.js, providing a centralized store and predictable state mutations for large applications.

12. What are lifecycle hooks in Vue?

Lifecycle hooks are methods called at different stages of a component’s life, like created(), mounted(), updated(), and unmounted().

13. How can you optimize performance in Vue?

  • Use lazy loading for components
  • Use v-once directive for static content
  • Use key attribute in lists
  • Use computed properties instead of methods for expensive operations
  • Avoid unnecessary watchers

14. What is a watcher in Vue?

A watcher observes a reactive data source and runs a callback when the data changes, useful for asynchronous or expensive operations.

15. Explain the difference between computed and methods.

  • computed properties are cached based on dependencies and only re-evaluate when needed.
  • methods are called every time they are invoked without caching.

16. What is a slot in Vue?

Slots allow you to pass content from a parent component into a child component's template, enabling flexible and reusable components.

17. How does Vue handle event modifiers?

Event modifiers like .stop, .prevent, .capture modify event behavior directly in the template, e.g., v-on:click.stop stops event propagation.

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

  • v-if conditionally renders or destroys the DOM elements.
  • v-show toggles the visibility by changing the CSS display property but keeps elements in the DOM.

19. How can you use TypeScript with Vue?

Vue 3 has built-in TypeScript support. You can define component props and state with types and use the Composition API for better typing.

20. What are some best practices for Vue development?

  • Use components for modularity
  • Use the Composition API for reusable logic
  • Keep templates clean and simple
  • Use Vue DevTools for debugging
  • Manage state properly with Vuex or Pinia
  • Write unit tests for components