#Components props?
3 messages · Page 1 of 1 (latest)
Hi @silent iris. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
To pass values to a component in Nuxt, you can use props. Here's how you can do it:
- Define props in the child component:
In your child component, use defineProps to declare the props it expects to receive:
<script setup>
const props = defineProps({
myProp: String
})
</script>
- Pass values from the parent component:
In the parent component, you can pass values to the child component using the defined prop names:
<template>
<ChildComponent myProp="Hello World" />
</template>
You can also bind dynamic values using the v-bind directive or its shorthand ::
<template>
<ChildComponent :myProp="dynamicValue" />
</template>
For more complex data types like objects or arrays, you can pass them as JSON strings and use the : prefix to automatically decode them:
<template>
<ChildComponent :complexProp='{"key": "value"}' />
</template>
These methods are described in the Nuxt Content documentation.
Additionally, when using <NuxtPage>, you can pass custom props that will be available in your page components:
<template>
<NuxtPage :customProp="123" />
</template>
You can then access this prop in your page component as described in the Nuxt documentation.