Skip to content

What Is Reactivity in Vue?

In Vue, reactivity is the system that makes an application respond to data changes automatically. It is the foundation of Vue and lets an application manage its state effectively. The main features of the reactivity system:

  1. Reactive data: Vue watches the application's data model and detects changes automatically. This data is usually defined in a component's data function.
  2. Dependency tracking: Vue tracks where each piece of data is used, so when it changes, every component and calculation that depends on it is updated.
  3. Reactive getters and setters: Vue uses getters and setters to make data reactive; they run when data is read and when it changes, which triggers the reactivity system.
  4. Computed properties: reactive properties that depend on other data and are recalculated when it changes. They are efficient because they recalculate only when their dependencies change.
  5. Watchers: track changes to specific data and respond to them, for example triggering an operation when a value changes.
  6. Asynchronous updates: Vue processes data changes asynchronously: changes are queued and applied efficiently in a batch.

Thanks to reactivity, Vue gives developers a strong, intuitive link between data and user interface for building dynamic, interactive web applications.

Note: Vue 2 achieved reactivity with getters and setters defined through Object.defineProperty; Vue 3 uses JavaScript Proxy objects. This lets Vue 3 track properties added to an object later and array indexes automatically.

Have a question about this article? Write to me