← Vue.js learning pathVue.js · Module 3 of 10
Reactivity with ref and reactive
Create reactive state using the Composition API.
📖 Key ideas
- ref(0) creates a reactive value; use .value in script.
- reactive({}) makes a reactive object.
- In templates, refs unwrap automatically (no .value).
- <script setup> is the concise Composition API syntax.
- Vue tracks which components use which data.
💡 Real-life example: ref is a box with a bell: whenever you change what is inside, everyone listening hears it.
ref()Reactive wrapper for any value
reactive()Reactive object
.valueAccess a ref in script
<script setup>Compact Composition API syntax