目录

Using a Custom Component

Declare the reference in the JSON file of the page. That is, set the tag name and corresponding component path in the usingComponents field.

// page/index.js
{
  "usingComponents": {
    "my-component": "./components/my-component/my-component"
  }
}

In the HXML file of the page, you can use custom components in the same way as using basic components. The node name is the tag name of the custom component.

<!--index.hxml -->
<view>
  <my-component />
</view>
  • The custom component declared in the usingComponents field of the app.json file is a global component, which can be directly used in all pages and custom components.
  • A custom component can use the usingComponents field to reference another custom component in the same way that a page does.