Skip to main content
InterviewHubPRO
Section Overview
Q8

Question 8 of 50

Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

16%
Vue.js & Composition API (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

How does Two-Way Data Binding work with `v-model` and `defineModel()`?

junior LevelCode ExampleComponents

In Simple Words:

  • In Vue 2: v-model was limited to a single property (value + input event).
  • In Vue 3: A component can have multiple v-model bindings:
    html
    <UserCard v-model:first-name="first" v-model:last-name="last" />
    
  • defineModel() (Vue 3.4+): Eliminates tedious manual prop declaration and event emission:
    vue
    <!-- CustomInput.vue -->
    <script setup>
    const model = defineModel<string>();
    </script>
    <template>
      <input v-model="model" />
    </template>