SoFunction
Updated on 2025-04-12

Analysis on the difference between v-model:value and v-model of vue3 component

In Vue 3,v-modelis a syntax sugar used to implement two-way data binding, andv-model:valueyesv-modelThe explicit form allows you to specify the bound property name. Their main differences are flexibility and default behavior. The following is a detailed comparison:

1. Default behavior

  • v-model
    • By default,v-modelWill bind to child componentsmodelValueProperties andupdate:modelValueevent.
    • This is the default behavior of Vue 3 and works for most scenarios, especially simple form input bindings.

Example

<template>
  <ChildComponent v-model="parentValue" />
</template>
<script>
import ChildComponent from './';
export default {
  components: { ChildComponent },
  data() {
    return {
      parentValue: 'Hello'
    };
  }
};
</script>

In the child component:

<template>
  <input :value="modelValue" @input="$emit('update:modelValue', $)" />
</template>
<script>
export default {
  props: ['modelValue'],
  emits: ['update:modelValue']
};
</script>
  • v-model:value
    • v-model:valueyesv-modelThe explicit form allows you to specify the binding attribute and event name explicitly.
    • This method is more flexible and suitable for scenarios where custom binding properties are required.

Example

<template>
  <ChildComponent v-model:value="parentValue" />
</template>

In the child component:

<template>
  <input :value="customValue" @input="$emit('update:value', $)" />
</template>
<script>
export default {
  props: ['value'],
  emits: ['update:value']
};
</script>

2. Flexibility

  • v-model
    • Default binding tomodelValueandupdate:modelValue, suitable for most standard scenarios.
    • If you need to bind multiple attributes, you need to usev-model:[arg]Form (e.g.v-model:title)。
  • v-model:value
    • Explicitly specify bound properties and events, suitable for scenarios where custom attribute names are required.
    • For example, if your child component uses a custom onevalueProperties instead of defaultmodelValue, you need to usev-model:value

3. Multi-model binding

In Vue 3,v-modelMulti-model binding is supported, but it needs to be implemented in an explicit form.

  • v-model
    • Default binding tomodelValue, but can be extended to multi-model binding by parameters.
<ChildComponent v-model:title="title" v-model:content="content" />
  • v-model:value
    • Explicit binding, expressing bound properties and events more clearly.
<ChildComponent v-model:value="parentValue" />

4. Usage scenarios

  • v-model
    • Suitable for most standard scenarios, especially form input binding.
    • Simple and easy to use, complies with Vue's default behavior.
  • v-model:value
    • Suitable for scenarios where custom binding properties are required.
    • Provides greater flexibility, especially when dealing with complex subcomponents.

Summarize

  • If your child component uses the defaultmodelValueandupdate:modelValue,usev-modelJust do it.
  • If you need to customize the binding property name (such asvalueor other custom properties), usev-model:valueorv-model:[arg]
  • For multi-model binding, parameterizedv-model:[arg]form to keep the code clear and consistent.

In Vue 3,v-model:valueProvides a more flexible binding method, but the default onev-modelStill the most commonly used form.

This is the end of this article about the difference between v-model:value and v-model in vue3 components. For more information about the differences between vue3 v-model:value and v-model, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!