Back
VueMediumNew

What is the Composition API and why was it introduced?

Consider code organization and logic reuse across large components

Ideal Answer

The Composition API is a set of function-based APIs (ref, reactive, computed, watch, lifecycle hooks, etc.) that let you organize a component's logic by concern rather than by option type. It was introduced to solve two main problems with the Options API:

  1. Logic reuse: Previously, sharing stateful logic between components required mixins, which caused naming collisions and unclear data sources. Composables solve this cleanly.
  2. Code organization in large components: In the Options API, logic for a single feature is spread across data, computed, methods, and watch. The Composition API lets you group all code related to one feature together.

It's typically used with <script setup> for concise syntax.