Published on

ref() vs reactive() in Vue 3

Authors
  • avatar
    Name
    Gene Zhang
    Twitter

https://vuejs.org/guide/essentials/reactivity-fundamentals.html#reactive

Unlike a ref which wraps the inner value in a special object, reactive() makes an object itself reactive.

It only works for object types (objects, arrays, and collection types such as Map and Set).

import { reactive } from 'vue'

const state = reactive({ count: 0 })
<button @click="state.count++">{{ state.count }}</button>