Props
Vue components require explicit props declaration. In <script setup>, use defineProps(). In non-<script setup>, use the props option or an object syntax.
<script setup>
const props = defineProps(['foo']);
console.log(props.foo);
</script>
<script>
export default {
props: ['foo'],
setup(props) {
console.log(props.foo);
}
};
</script>Prop Passing Details
Prop Name Casing
Use camelCase for long prop names:
defineProps({
greetingMessage: String
})When passing to a child component, use kebab-case:
Static vs. Dynamic Props
Pass props statically or dynamically:
Passing Different Value Types
Pass various types:
One-Way Data Flow
Props create a one-way-down binding, preventing child components from mutating the parent's state.
Mutating Object / Array Props
Avoid mutating objects/arrays passed as props.
Prop Validation
Validate props with an object:
Last updated