What Is the Vue Options API?

Vue's Options API is a way of defining Vue components. It has been the basic way to define components since Vue's first versions. When you create a component you define various options that describe how it behaves: its data, props, computed properties, methods, lifecycle hooks and more.
Some of the main options:
- Data: the component's reactive data, which updates the user interface dynamically.
- Methods: the component's methods, for example event handlers.
- Computed: computed properties — new reactive values derived from other data.
- Watch: watches specific data or computed properties and runs a function when they change.
- Props: data passed in from outside, important for passing data from parent to child.
- Lifecycle hooks: functions that run at various stages of the component's life (for example created, mounted, updated, destroyed).
- Components: the child components used inside this component.
- Directives: custom Vue directives.
- Filters: text-formatting filters (removed in Vue 3).
The Options API is the foundation of Vue and offers a simple, understandable structure. Vue 3 introduced the Composition API as well, but the Options API is still widely used: the Composition API gives larger, more complex applications more flexibility and organisation, while the Options API is a good choice for getting started simply and quickly.
Note (Vue 3): In Vue 3 the destroyed hook was renamed to unmounted, and beforeDestroy to beforeUnmount.
Have a question about this article? Write to me


