目录

Component Template and Data Binding

Component Template

The syntax of the component template is the same as that of the page template. The node tree generated by combining the component template and component data is rendered at the reference position.

In the component template, the slot tag is used to pass the child node content.

Example:

<!--Component HXML-->
<view class="custom">
  <view>Internal node of the component</view>
  <slot></slot>
</view>
<!--Page HXML-->
<view>
  <my-component>
    <!-- Content in the position of the slot tag -->
    <view>Content inserted into the slot tag</view>
  </my-component>
</view>

Binding Template Data

Just like in a regular HXML template, you can use data binding to pass dynamic data to child component properties.

Example:

<view>
  <my-component propA={{pagePropA}}>
    <view>Example of binding component template data</view>
  </my-component>
</view>

In the preceding example, the component property propA receives the data pagePropA passed from the page. You can use setData to change the bound data field.