Vue.js Interview Questions Hindi mein

Vue.js कोर्स के 25 सवाल, हर सवाल के सही जवाब और explanation के साथ। जवाब देखने से पहले ख़ुद सोचें।

Vue Foundations

1. Why is Vue described as a progressive framework?

  1. It upgrades itself automatically
  2. It only supports progressive web apps
  3. You can adopt it incrementally, from one widget to a full application
  4. It renders pages progressively from the server only
जवाब देखें

जवाब: You can adopt it incrementally, from one widget to a full application

Use as much of Vue as the project needs.

पाठ: What Vue Is

2. Which command scaffolds an official Vite-based Vue project?

  1. npm create vue@latest
  2. npm install vue-starter --global
  3. vue new project
  4. npx create-react-app --vue
जवाब देखें

जवाब: npm create vue@latest

create-vue is the official scaffolding tool.

पाठ: Setting Up a Vue Project

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

  1. v-if only works on components
  2. They are identical aliases
  3. v-show removes the element from the DOM
  4. v-if adds or removes the element; v-show only toggles its CSS display
जवाब देखें

जवाब: v-if adds or removes the element; v-show only toggles its CSS display

Choose v-show for frequent toggles, v-if for rarely shown content.

पाठ: Template Syntax

Reactivity

4. Why does destructuring a reactive() object into local variables cause problems?

  1. It throws a runtime error
  2. The local variables are plain values and are no longer reactive
  3. It deep-copies the whole store
  4. It makes the object read-only
जवाब देखें

जवाब: The local variables are plain values and are no longer reactive

Reactivity lives on the Proxy, not on copied values; toRefs can help.

पाठ: ref and reactive

5. When does a computed getter re-run?

  1. On every component render
  2. Only when one of its reactive dependencies changes
  3. Every second on a timer
  4. Only when called with new arguments
जवाब देखें

जवाब: Only when one of its reactive dependencies changes

Computed values are cached.

पाठ: Computed Properties

6. How does watchEffect know what to watch?

  1. It only watches props
  2. You pass an array of dependencies
  3. It watches every ref in the component
  4. It tracks the reactive values read while its function runs
जवाब देखें

जवाब: It tracks the reactive values read while its function runs

Automatic dependency tracking.

पाठ: watch and watchEffect

Components

7. How should a child component request a change to data it received as a prop?

  1. Emit an event so the parent updates its own state
  2. Assign a new value to the prop
  3. Use v-html on the prop
  4. Call the parent component method directly by name
जवाब देखें

जवाब: Emit an event so the parent updates its own state

Props are read-only in the child.

पाठ: Props and Emits

8. What does v-model on a custom component expand to by default?

  1. A shared global variable
  2. A value prop and a change event on window
  3. A modelValue prop and an update:modelValue event
  4. A two-way Proxy between parent and child
जवाब देखें

जवाब: A modelValue prop and an update:modelValue event

defineModel wraps this pair for you.

पाठ: v-model on Components

9. What do scoped slots add compared with ordinary slots?

  1. They limit slots to one per component
  2. They apply scoped CSS to the slot
  3. The child can pass data to the slot content provided by the parent
  4. They render slot content on the server only
जवाब देखें

जवाब: The child can pass data to the slot content provided by the parent

Slot props flow from child to parent template.

पाठ: Slots

Composition Patterns

10. Why do composables usually return an object of refs rather than a reactive object?

  1. So callers can destructure the result and keep reactivity
  2. Refs use less memory
  3. Reactive objects cannot be returned from functions
  4. Templates cannot read reactive objects
जवाब देखें

जवाब: So callers can destructure the result and keep reactivity

Destructuring a reactive object loses reactivity.

पाठ: Composables

11. Where should code that reads the rendered DOM run?

  1. In defineProps
  2. At the top level of script setup
  3. Inside a computed getter
  4. Inside onMounted
जवाब देखें

जवाब: Inside onMounted

The DOM exists only after mounting.

पाठ: Lifecycle Hooks

12. What problem does provide/inject mainly solve?

  1. Fetching data from a server
  2. Prop drilling through components that do not need the data
  3. Styling child components
  4. Routing between pages
जवाब देखें

जवाब: Prop drilling through components that do not need the data

Ancestors share values with any descendant.

पाठ: provide and inject

Forms and Styling

13. What does the .number modifier on v-model do?

  1. Allows only digits to be typed
  2. Casts the input value to a number
  3. Formats the number with separators
  4. Validates that the value is positive
जवाब देखें

जवाब: Casts the input value to a number

Input values are strings by default.

पाठ: Form Bindings and Validation

14. What does `<style scoped>` do?

  1. Makes the styles global
  2. Loads the CSS only on mobile
  3. Inlines every rule as a style attribute
  4. Limits the CSS rules to the component's own elements
जवाब देखें

जवाब: Limits the CSS rules to the component's own elements

Vue adds a unique attribute to scope selectors.

पाठ: Class and Style Bindings, Scoped CSS

15. Which classes define the starting state of an entering element and the end state of a leaving one with name="fade"?

  1. fade-enter-from and fade-leave-to
  2. fade-in and fade-out
  3. fade-start and fade-end
  4. v-show-enter and v-show-leave
जवाब देखें

जवाब: fade-enter-from and fade-leave-to

The name prop replaces the v- prefix.

पाठ: Transitions

Routing With Vue Router

16. Why should a page watch route.params.id?

  1. RouterLink does not update the URL
  2. Params are only available after a reload
  3. The same component instance is reused when only the params change
  4. route.params is not reactive
जवाब देखें

जवाब: The same component instance is reused when only the params change

Lifecycle hooks like onMounted do not run again.

पाठ: Vue Router Basics

17. What does returning false from a beforeEach guard do?

  1. Redirects to the home route
  2. Reloads the page
  3. Cancels the navigation
  4. Skips the remaining guards and continues
जवाब देखें

जवाब: Cancels the navigation

Return a route location to redirect instead.

पाठ: Navigation Guards and Lazy Routes

18. Where does a child route component render?

  1. In the RouterView inside the parent route's component
  2. Always in the RouterView of App.vue
  3. In a new browser tab
  4. Nowhere until it is registered globally
जवाब देखें

जवाब: In the RouterView inside the parent route's component

Each level of nesting needs its own RouterView.

पाठ: Nested Routes and Route Meta

State, Data and TypeScript

19. Why use storeToRefs when destructuring a Pinia store?

  1. To register the store with the router
  2. To make actions run faster
  3. To persist the store to localStorage
  4. To keep state and getters reactive after destructuring
जवाब देखें

जवाब: To keep state and getters reactive after destructuring

Plain destructuring copies values.

पाठ: Pinia Stores

20. Why does the composable call toValue(url) inside watchEffect?

  1. To convert the URL to lowercase
  2. So the effect tracks a ref or getter argument and refetches when it changes
  3. To cache the response forever
  4. Because fetch only accepts refs
जवाब देखें

जवाब: So the effect tracks a ref or getter argument and refetches when it changes

Reading the reactive source inside the effect registers it as a dependency.

पाठ: Fetching Data

21. Which tool type-checks .vue files from the command line?

  1. tsc alone, with no plugins
  2. vue-tsc
  3. vite build
  4. eslint --fix
जवाब देखें

जवाब: vue-tsc

vue-tsc wraps TypeScript with Vue file support.

पाठ: TypeScript With Vue

Vue in Production

22. Why is wrapper.find(...).trigger("click") awaited in a test?

  1. Clicks are simulated with a delay of one second
  2. trigger sends a network request
  3. Vitest requires every call to be awaited
  4. Vue updates the DOM asynchronously, and the promise resolves after the update
जवाब देखें

जवाब: Vue updates the DOM asynchronously, and the promise resolves after the update

Awaiting lets the re-render finish.

पाठ: Testing With Vitest and Vue Test Utils

23. What is the main effect of wrapping a component in `<KeepAlive>`?

  1. Its instance is cached when hidden, so state is preserved when shown again
  2. It is rendered on the server
  3. Its props become read-only
  4. It is loaded in a separate chunk
जवाब देखें

जवाब: Its instance is cached when hidden, so state is preserved when shown again

Cached instances fire onActivated and onDeactivated.

पाठ: Performance Techniques

24. Why should code that uses window or localStorage go in onMounted in an SSR app?

  1. window is faster inside lifecycle hooks
  2. onMounted runs before the server responds
  3. onMounted runs only in the browser, not during server rendering
  4. SSR disables all other hooks
जवाब देखें

जवाब: onMounted runs only in the browser, not during server rendering

The server has no browser globals.

पाठ: Nuxt and Server-Side Rendering

25. Which item belongs on a Vue release checklist?

  1. Route guards replace server-side authorisation
  2. Props are mutated directly in children for speed
  3. Lists rendered with v-for use stable unique keys
  4. v-html is used for all user comments
जवाब देखें

जवाब: Lists rendered with v-for use stable unique keys

Correct, safe and maintainable apps.

पाठ: A Vue Release Checklist

← कोर्स पर वापस जाएँ