目录

Placeholder Component

When the asynchronous package splitting or render-time injection feature is used, other custom components referenced by a custom component may be unavailable during initial rendering. To ensure that the rendering process proceeds smoothly, you need to use placeholder components for unavailable custom components. The basic library uses placeholder components for rendering when referenced custom components are unavailable and reverts to the custom components when they are ready.

The placeholder component of a custom component can be another custom component or a built-in component.

Constraints

Configuration

The componentPlaceholder field in the JSON configurations corresponding to a page or custom component is used to specify the placeholder component. The following is an example:

{
  "usingComponents": {
    "comp-a": "./comp/compA"
  },
  "componentPlaceholder": {
    "comp-a": "view"
  }
}

The configurations are described as follows:

The placeholder component of the comp-a component is a built-in View component.

If the corresponding template is configured as follows:

<comp-a>Placeholder component</comp-a>

compA.hxml in the comp directory:

<view>compA</view>

When the atomic service is started, the page is rendered as follows:

<view>Placeholder component</view>

The framework replaces the placeholder component only after the comp-a component is injected.

<view>compA</view>