Skip to content

Commit

Permalink
Explain v-model with :is and native elements (#1807)
Browse files Browse the repository at this point in the history
  • Loading branch information
skirtles-code committed Jun 28, 2022
1 parent 27497fa commit e653103
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/api/built-in-special-elements.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,24 @@ A "meta component" for rendering dynamic components or elements.

Registration is not required if you pass the component itself to `is` rather than its name, e.g. in `<script setup>`.

If `v-model` is used on a `<component>` tag, the template compiler will expand it to a `modelValue` prop and `update:modelValue` event listener, much like it would for any other component. However, this won't be compatible with native HTML elements, such as `<input>` or `<select>`. As a result, using `v-model` with a dynamically created native element won't work:

```vue
<script setup>
import { ref } from 'vue'
const tag = ref('input')
const username = ref('')
</script>
<template>
<!-- This won't work as 'input' is a native HTML element -->
<component :is="tag" v-model="username" />
</template>
```

In practice, this edge case isn't common as native form fields are typically wrapped in components in real applications. If you do need to use a native element directly then you can split the `v-model` into an attribute and event manually.

- **See also:** [Dynamic Components](/guide/essentials/component-basics.html#dynamic-components)

## `<slot>`
Expand Down

0 comments on commit e653103

Please sign in to comment.