--- title: Variables in Script Setup Are Not Reactive by Default impact: HIGH impactDescription: Forgetting to wrap variables with ref() or reactive() causes silent reactivity failures in script setup type: gotcha tags: [vue3, sfc, script-setup, reactivity, ref, composition-api] --- # Variables in Script Setup Are Not Reactive by Default **Impact: HIGH** - Unlike Options API's `data()` which automatically makes properties reactive, variables declared in ` ``` **Correct Code:** ```vue ``` ## Common Mistake: Plain Computed ```vue ``` ```vue ``` ## When to Use ref() vs reactive() ```vue ``` ## Template Automatic Unwrapping Vue automatically unwraps refs in templates: ```vue ``` But in event handlers written inline, you might still need `.value`: ```vue ``` ## Reference - [Vue.js Reactivity Fundamentals](https://vuejs.org/guide/essentials/reactivity-fundamentals.html) - [Vue.js ref()](https://vuejs.org/api/reactivity-core.html#ref) - [Vue.js reactive()](https://vuejs.org/api/reactivity-core.html#reactive)