Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Vue 3 debugging reference for reactivity issues, computed errors, watcher bugs, async failures, and SSR hydration problems.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
reference/ref-value-access.md
1---2title: Always Use .value When Accessing ref() in JavaScript3impact: HIGH4impactDescription: Forgetting .value causes silent failures and bugs in reactive state updates5type: capability6tags: [vue3, reactivity, ref, composition-api]7---89# Always Use .value When Accessing ref() in JavaScript1011**Impact: HIGH** - Forgetting `.value` causes silent failures where state updates don't trigger reactivity, leading to hard-to-debug issues.1213When using `ref()` in Vue 3's Composition API, the reactive value is wrapped in an object and must be accessed via `.value` in JavaScript code. However, in templates, Vue automatically unwraps refs so `.value` is not needed there. This inconsistency is a common source of bugs.1415## Task Checklist1617- [ ] Always use `.value` when reading or writing ref values in `<script>` or `.js`/`.ts` files18- [ ] Never use `.value` in `<template>` - Vue unwraps refs automatically there19- [ ] When passing refs to functions, decide whether to pass the ref object or `.value`20- [ ] Use IDE/TypeScript to catch missing `.value` errors early2122**Incorrect:**23```javascript24import { ref } from 'vue'2526const count = ref(0)2728// These do NOT work as expected29count++ // Tries to increment the ref object, not the value30count = 5 // Reassigns the variable, loses reactivity31console.log(count) // Logs "[object Object]", not the number3233const items = ref([1, 2, 3])34items.push(4) // Error: push is not a function35```3637**Correct:**38```javascript39import { ref } from 'vue'4041const count = ref(0)4243// Always use .value in JavaScript44count.value++ // Correctly increments to 145count.value = 5 // Correctly sets value to 546console.log(count.value) // Logs "5"4748const items = ref([1, 2, 3])49items.value.push(4) // Correctly adds 4 to the array50```5152```vue53<template>54<!-- In templates, NO .value needed - Vue unwraps automatically -->55<p>{{ count }}</p>56<button @click="count++">Increment</button>57</template>58```5960## Reference61- [Vue.js Reactivity Fundamentals - ref()](https://vuejs.org/guide/essentials/reactivity-fundamentals.html#ref)62