Vue.js & Composition API (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)
What is the difference between `ref()` and `reactive()` in Vue 3?
junior LevelVue & Nuxt
In Simple Words:
ref(value):- Works with primitives (strings, numbers, booleans) as well as objects.
- Wraps the value in a reactive container object with a
.valueproperty. - In
<script setup>, you must access.value(count.value++); in<template>, Vue unwraps it automatically (<button>{{ count }}</button>).
reactive(object):- Works only with objects and arrays (cannot take primitives).
- Returns a deeply reactive Proxy directly (no
.valueneeded). - Risk: Destructuring a reactive object (
const { x, y } = reactiveObj) destroys reactivity unless you usetoRefs().
- Industry Best Practice: Many teams standardize on using
ref()exclusively for consistency.