name
Explicitly declare a display name for the component.The name is used for:
- Recursive self-reference in the component’s own template
- Display in Vue DevTools’ component inspection tree
- Display in warning component traces
MyComponent.vue will have the inferred display name “MyComponent”.Another case is that when a component is registered globally with app.component, the global ID is automatically set as its name.The name option allows you to override the inferred name, or to explicitly provide a name when no name can be inferred (e.g., when not using build tools, or an inlined non-SFC component).There is one case where name is explicitly necessary: when matching against cacheable components in <KeepAlive> via its include / exclude props.Example:inheritAttrs
Controls whether default component attribute fallthrough behavior should be enabled.By default, parent scope attribute bindings that are not recognized as props will “fallthrough”. This means that when we have a single-root component, these bindings will be applied to the root element of the child component as normal HTML attributes. When authoring a component that wraps a target element or another component, this may not always be the desired behavior. By setting When using this component:With
inheritAttrs to false, this default behavior can be disabled.The attributes are available via the $attrs instance property and can be explicitly bound to a non-root element using v-bind.Example:inheritAttrs: false, the type and placeholder attributes will not be applied to the root <label> element, but instead will be applied to the <input> element via v-bind="$attrs".Note:- This option does not affect
classandstylebindings. - Since Vue 3.3+, when using
<script setup>, you can use thedefineOptions()macro to set this option:
components
An object that makes components available to the component instance.This option allows you to register components that will be available for use in the component’s template. The object’s keys will be used as the component names in templates, and the values should be the component definition objects.Example:Custom naming:Note: With Single-File Components using
<script setup>, imported components can be used directly in the template without registration:directives
An object that makes directives available to the component instance.This option allows you to register custom directives that will be available for use in the component’s template. The object’s keys will be used as the directive names, and the values should be the directive definition objects or functions.Example:Directive object with lifecycle hooks:Directive Definition:A directive definition object can provide several hook functions (all optional):
created: Called before the element’s attributes or event listeners are appliedbeforeMount: Called when the directive is first bound to the element and before parent component is mountedmounted: Called when the bound element’s parent component is mountedbeforeUpdate: Called before the containing component’s VNode is updatedupdated: Called after the containing component’s VNode and the VNodes of its children have updatedbeforeUnmount: Called before the bound element’s parent component is unmountedunmounted: Called when the directive is unbound from the element and the parent component is unmounted
<script setup>, any camelCase variable that starts with the v prefix can be used as a custom directive: