Glossary

This glossary is intended to provide some guidance about the meanings of technical terms that are in common usage when talking about Vue. It is intended to be descriptive of how terms are commonly used, not a prescriptive specification of how they must be used. Some terms may have slightly different meanings or nuances depending on the surrounding context.

[[TOC]]

async component

An async component is a wrapper around another component that allows for the wrapped component to be lazy loaded. This is typically used as a way to reduce the size of the built .js files, allowing them to be split into smaller chunks that are loaded only when required.

Vue Router has a similar feature for the lazy loading of route components, though this does not use Vue's async components feature.

For more details see:

compiler macro

A compiler macro is special code that is processed by a compiler and converted into something else. They are effectively a clever form of string replacement.

Vue's SFC compiler supports various macros, such as defineProps(), defineEmits() and defineExpose(). These macros are intentionally designed to look like normal JavaScript functions so that they can leverage the same parser and type inference tooling around JavaScript / TypeScript. However, they are not actual functions that are run in the browser. These are special strings that the compiler detects and replaces with the real JavaScript code that will actually be run.

Macros have limitations on their use that don't apply to normal JavaScript code. For example, you might think that const dp = defineProps would allow you to create an alias for defineProps, but it'll actually result in an error. There are also limitations on what values can be passed to defineProps(), as the 'arguments' have to be processed by the compiler and not at runtime.

For more details see:

component

The term component is not unique to Vue. It is common to many UI frameworks. It describes a chunk of the UI, such as a button or checkbox. Components can also be combined to form larger components.

Components are the primary mechanism provided by Vue to split a UI into smaller pieces, both to improve maintainability and to allow for code reuse.

A Vue component is an object. All properties are optional, but either a template or render function is required for the component to render. For example, the following object would be a valid component:

const HelloWorldComponent = {
  render() {
    return 'Hello world!'
  }
}

In practice, most Vue applications are written using Single-File Components (.vue files). While these components may not appear to be objects at first glance, the SFC compiler will convert them into an object, which is used as the default export for the file. From an external perspective, a .vue file is just an ES module that exports a component object.

The properties of a component object are usually referred to as options. This is where the Options API gets its name.

The options for a component define how instances of that component should be created. Components are conceptually similar to classes, though Vue doesn't use actual JavaScript classes to define them.

The term component can also be used more loosely to refer to component instances.

For more details see:

The word 'component' also features in several other terms:

composable

The term composable describes a common usage pattern in Vue. It isn't a separate feature of Vue, it's just a way of using the framework's Composition API.

  • A composable is a function.
  • Composables are used to encapsulate and reuse stateful logic.
  • The function name usually begins with use, so that other developers know it's a composable.
  • The function is typically expected to be called during the synchronous execution of a component's setup() function (or, equivalently, during the execution of a <script setup> block). This ties the invocation of the composable to the current component context, e.g. via calls to provide(), inject() or onMounted().
  • Composables typically return a plain object, not a reactive object. This object usually contains refs and functions and is expected to be destructured within the calling code.

As with many patterns, there can be some disagreement about whether specific code qualifies for the label. Not all JavaScript utility functions are composables. If a function doesn't use the Composition API then it probably isn't a composable. If it doesn't expect to be called during the synchronous execution of setup() then it probably isn't a composable. Composables are specifically used to encapsulate stateful logic, they are not just a naming convention for functions.

See Guide - Composables for more details about writing composables.

Composition API

The Composition API is a collection of functions used to write components and composables in Vue.

The term is also used to describe one of the two main styles used to write components, the other being the Options API. Components written using the Composition API use either <script setup> or an explicit setup() function.

See the Composition API FAQ for more details.

custom element

A custom element is a feature of the Web Components standard, which is implemented in modern web browsers. It refers to the ability to use a custom HTML element in your HTML markup to include a Web Component at that point in the page.

Vue has built-in support for rendering custom elements and allows them to be used directly in Vue component templates.

Custom elements should not be confused with the ability to include Vue components as tags within another Vue component's template. Custom elements are used to create Web Components, not Vue components.

For more details see:

directive

The term directive refers to template attributes beginning with the v- prefix, or their equivalent shorthands.

Built-in directives include v-if, v-for, v-bind, v-on and v-slot.

Vue also supports creating custom directives, though they are typically only used as an 'escape hatch' for manipulating DOM nodes directly. Custom directives generally can't be used to recreate the functionality of the built-in directives.

For more details see:

dynamic component

The term dynamic component is used to describe cases where the choice of which child component to render needs to be made dynamically. Typically, this is achieved using <component :is="type">.

A dynamic component is not a special type of component. Any component can be used as a dynamic component. It is the choice of component that is dynamic, rather than the component itself.

For more details see:

effect

See reactive effect and side effect.

event

The use of events for communicating between different parts of a program is common to many different areas of programming. Within Vue, the term is commonly applied to both native HTML element events and Vue component events. The v-on directive is used in templates to listen for both types of event.

For more details see:

fragment

The term fragment refers to a special type of VNode that is used as a parent for other VNodes, but which doesn't render any elements itself.

The name comes from the similar concept of a DocumentFragment in the native DOM API.

Fragments are used to support components with multiple root nodes. While such components might appear to have multiple roots, behind the scenes they use a fragment node as a single root, as a parent of the 'root' nodes.

Fragments are also used by the template compiler as a way to wrap multiple dynamic nodes, e.g. those created via v-for or v-if. This allows for extra hints to be passed to the VDOM patching algorithm. Much of this is handled internally, but one place you may encounter this directly is using a key on a <template> tag with v-for. In that scenario, the key is added as a prop to the fragment VNode.

Fragment nodes are currently rendered to the DOM as empty text nodes, though that is an implementation detail. You may encounter those text nodes if you use $el or attempt to walk the DOM with built-in browser APIs.

functional component

A component definition is usually an object containing options. It may not appear that way if you're using <script setup>, but the component exported from the .vue file will still be an object.

A functional component is an alternative form of component that is declared using a function instead. That function acts as the render function for the component.

A functional component cannot have any state of its own. It also doesn't go through the usual component lifecycle, so lifecycle hooks can't be used. This makes them slightly lighter than normal, stateful components.

For more details see:

hoisting

The term hoisting is used to describe running a section of code before it is reached, ahead of other code. The execution is 'pulled up' to an earlier point.

JavaScript uses hoisting for some constructs, such as var, import and function declarations.

In a Vue context, the compiler applies hoisting to improve performance. When compiling a component, static values are moved out of the component's scope. These static values are described as 'hoisted' because they are created outside the component.

cache static

The term cache is used to describe the temporary storage of frequently accessed data to improve performance.

The Vue template compiler identifies those static VNodes, caches them during the initial render, and reuses the same VNodes for every subsequent re-render.

For more details see:

in-DOM template

There are various ways to specify a template for a component. In most cases the template is provided as a string.

The term in-DOM template refers to the scenario where the template is provided in the form of DOM nodes, instead of a string. Vue then converts the DOM nodes into a template string using innerHTML.

Typically, an in-DOM template starts off as HTML markup written directly in the HTML of the page. The browser then parses this into DOM nodes, which Vue then uses to read off the innerHTML.

For more details see:

inject

See provide / inject.

lifecycle hooks

A Vue component instance goes through a lifecycle. For example, it is created, mounted, updated, and unmounted.

The lifecycle hooks are a way to listen for these lifecycle events.

With the Options API, each hook is provided as a separate option, e.g. mounted. The Composition API uses functions instead, such as onMounted().

For more details see:

macro

See compiler macro.

named slot

A component can have multiple slots, differentiated by name. Slots other than the default slot are referred to as named slots.

For more details see:

Options API

Vue components are defined using objects. The properties of these component objects are known as options.

Components can be written in two styles. One style uses the Composition API in conjunction with setup (either via a setup() option or <script setup>). The other style makes very little direct use of the Composition API, instead using various component options to achieve a similar result. The component options that are used in this way are referred to as the Options API.