Performance: Reactivity transform and limitations
This affects how Vue tracks reactive dependencies and updates the DOM efficiently during user interactions.
<script setup lang="ts" reactivity-transform> let count = $ref(0); function increment() { count++; } </script>
import { ref } from 'vue'; export default { setup() { const count = ref(0); function increment() { count.value++; } return { count, increment }; } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Explicit ref with .value | Minimal extra nodes | 1 reflow per update | Low paint cost | [OK] Good |
| Reactivity transform with primitives | Minimal extra nodes | 1 reflow per update | Low paint cost | [OK] Good |
| Reactivity transform with nested objects | Potential missed updates | Possible extra reflows due to manual fixes | Medium paint cost | [!] |
| Using reactive() for nested objects | Minimal extra nodes | 1 reflow per update | Low paint cost | [OK] Good |
.value on refs..value on refs. correctly states this benefit. Other options are incorrect or unrelated.$ref to declare reactive variables.$ref(0), which is correct. const count = ref(0) uses classic ref, not Reactivity Transform. Options A, C, and D are incorrect for primitives.import { $ref } from 'vue'
const count = $ref(1)
count++
console.log(count)import { $reactive } from 'vue'
const state = $reactive({ count: 0 })
state.count++
console.log(state.count)Pass the test and this pattern moves unknown