Suggest an editImprove this articleRefine the answer for “How do you declare props in setup?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)In `setup()` (or `<script setup>`), props are declared differently than in the Options API: Vue 3 offers two approaches - receiving them as the first argument of `setup(props)`, or declaring them via `defineProps()`. **Key point:** props from `setup(props)` cannot be destructured directly without `toRefs()`, while `defineProps()` in `<script setup>` allows this safely because the Vue compiler wraps the properties in `toRefs` for you.Shown above the full answer for quick recall.Answer (EN)ImageIn `setup()` (or `<script setup>`), props are declared **differently than in the Options API**. Vue 3 has **two approaches**, and it is important to understand both for interviews. --- ## 1. The regular way inside setup() In a component with `setup()`, props are received **as the first argument**: ```js export default { props: { title: String, count: Number }, setup(props) { console.log(props.title) console.log(props.count) return {} } } ``` #### Features: - `props` is a **reactive object**, but NOT `reactive()`: it cannot be modified inside the component (it is read-only). - You can use it as `props.title`, `props.count`. - You cannot destructure it directly (reactivity would be lost!). --- ## You cannot do this (reactivity is lost): ```js const { title } = props // no more reactivity ``` #### You need to use toRefs: ```js import { toRefs } from 'vue' setup(props) { const { title, count } = toRefs(props) return { title, count } } ``` Now `title.value` is reactive. --- ## 2. The `<script setup>` way (recommended) In `<script setup>`, props are declared via `defineProps()`: ```vue <script setup> const props = defineProps({ title: String, count: Number, }) </script> ``` #### Usage: ```vue <template> <h1>{{ props.title }}</h1> </template> ``` You can destructure it right away, but carefully: ```vue <script setup> const { title, count } = defineProps({ title: String, count: Number }) </script> ``` In `<script setup>`, destructuring **preserves reactivity**, because the Vue compiler wraps it in `toRefs` for you. This is officially supported. --- ## Example of a complete component ```vue <script setup> import { computed } from 'vue' const { price, quantity } = defineProps({ price: Number, quantity: Number }) const total = computed(() => price * quantity) </script> <template> <p>Total: {{ total }}</p> </template> ``` --- ## Summary (perfect for an interview) #### Option 1: setup(props) ```js setup(props) { props.title } ``` - props are available via the first argument - cannot be destructured without `toRefs` #### Option 2: `<script setup>` + defineProps() ```js const props = defineProps({...}) ``` - automatic typing - can be destructured (Vue does the same thing as toRefs)For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.