docs: mention #components import for dynamic component (#22231)

This commit is contained in:
Julien Huang 2023-07-20 11:55:11 +02:00 committed by GitHub
parent 1f1de38d03
commit 6c517e919c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -98,17 +98,20 @@ This registers the components using the same strategy as used in Nuxt 2. For exa
## Dynamic Components ## Dynamic Components
If you want to use the Vue `<component :is="someComputedComponent">` syntax, then you will need to use the `resolveComponent` helper provided by Vue. If you want to use the Vue `<component :is="someComputedComponent">` syntax, you need to use the `resolveComponent` helper provided by Vue or import the component directly from `#components` and pass it into `is` prop.
For example: For example:
```vue ```vue
<script setup lang="ts"> <script setup lang="ts">
import { SomeComponent } from '#components'
const MyButton = resolveComponent('MyButton') const MyButton = resolveComponent('MyButton')
</script> </script>
<template> <template>
<component :is="clickable ? MyButton : 'div'" /> <component :is="clickable ? MyButton : 'div'" />
<component :is="SomeComponent" />
</template> </template>
``` ```