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-modelwas limited to a single property (value+inputevent). - In Vue 3: A component can have multiple
v-modelbindings: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>