📢 This article was translated by gemini-3-flash-preview
Defining Options API Options
Vue 3.3 introduced the defineOptions() macro. It allows you to define Options API options (like name) without needing a separate script block, excluding props, emits, expose, and slots (which have their own dedicated define macros).
| |
Why use name?
- Debugging: The component name shows up in Vue DevTools.
- Recursive Components: Allows a component to call itself using its name.
<keep-alive>: Enables filtering which components to cache usingincludeorexclude.
Two-Way Binding Between Parent and Child
Implementing two-way data binding used to be a bit verbose.
In the parent component:
| |
In the child component (the old way):
| |
With the defineModel() macro, it becomes much cleaner. The child component can be refactored to:
| |