Skip to content

Commit

Permalink
docs: add docs for v-model update:* event (#2839)
Browse files Browse the repository at this point in the history
docs: add docs for v-model update:* event
  • Loading branch information
xiaodong2008 committed May 1, 2024
1 parent c86beff commit 288f7bf
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/guide/components/v-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const model = defineModel()
This is how you would implement the same child component shown above prior to 3.4:

```vue
<!-- Child.vue -->
<script setup>
const props = defineProps(['modelValue'])
const emit = defineEmits(['update:modelValue'])
Expand All @@ -72,6 +73,16 @@ const emit = defineEmits(['update:modelValue'])
</template>
```

Then, `v-model="modelValue"` in the parent component will be compiled to:

```vue-html
<!-- Parent.vue -->
<Child
:modelValue="foo"
@update:modelValue="$event => (foo = $event)"
/>
```

As you can see, it is quite a bit more verbose. However, it is helpful to understand what is happening under the hood.

Because `defineModel` declares a prop, you can therefore declare the underlying prop's options by passing it to `defineModel`:
Expand Down

0 comments on commit 288f7bf

Please sign in to comment.