Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Vue 3 is Attribute

Vue 3 is Attribute

Vue3 Built-in Properties Vue 3 Built-in Attributes


is The is attribute is the core attribute for implementing dynamic components in Vue, used to dynamically specify which component the current element should render as.


Basic Explanation

is The is attribute is mainly used in dynamic component scenarios, allowing you to dynamically switch between different components for rendering at runtime based on data. This is the primary way to implement dynamic component functionality in Vue.


Basic Usage

1. Dynamic Component Switching

Use The element works with is attribute to implement dynamic components:

Example

2. Using a Component Object

The value of is can also be a component object directly:

Example


Use Cases

1. Tab Switching

Achieve an effect similar to tab switching:

Example

2. Conditionally Rendering Different Components

Dynamically select the component to render based on conditions:

Example


Using is on native elements

In Vue 3.1+, when is the attribute is used on a native HTML element, it is interpreted as the native Web platform's custom element feature.

But sometimes you need to replace a native element with a Vue component in a DOM template. For example, in

, using a custom component as a row:

Example

 

   

 

Use vue: prefix lets Vue render the element as a Vue component rather than a native HTML element.


Notes

Value of the is attribute: can be a component name string or a component object. When using a string, the component name should match the registered component name.

Using computed properties: can return different components based on complex conditional logic, enabling more flexible dynamic component switching.


Caching dynamic components with keep-alive

Use Wrapping dynamic components can cache component instances, avoiding re-creation on each switch:

Example

will cache the switched component instances; when the component is displayed again, it is restored directly from the cache rather than re-created.


Vue3 Built-in Properties Vue 3 Built-in Attributes