1# ContentSlot
2
3用于渲染并管理Native层使用C-API创建的组件。
4
5支持混合模式开发,当容器是ArkTS组件,子组件在Native侧创建时,推荐使用ContentSlot占位组件。
6
7> **说明:**
8>
9> 本模块首批接口从API version 12开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
10
11## 接口
12
13ContentSlot(content: Content)
14
15当内容添加到占位符组件时调用。
16
17**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
18
19**系统能力:** SystemCapability.ArkUI.ArkUI.Full
20
21**参数:**
22
23| 参数名  | 类型 | 必填 | 参数描述                                                     |
24| ------- | -------- | ---- | ------------------------------------------------------------ |
25| content | [Content](../js-apis-arkui-Content.md)  | 是   | Content作为ContentSlot的管理器,通过Native侧提供的接口,可以注册并触发ContentSlot的上下树事件回调以及管理ContentSlot的子组件。 |
26
27**示例:**
28
29下面的示例展示了ContentSlot的基本用法。
30
31```ts
32import { nativeNode } from 'libNativeNode.so' // 开发者自己实现的so
33import { NodeContent } from '@kit.ArkUI'
34
35@Entry
36@Component
37struct Parent {
38    private nodeContent: Content = new NodeContent();
39
40    aboutToAppear() {
41        // 通过C-API创建节点,并添加到管理器nodeContent上
42        nativeNode.createNativeNode(this.nodeContent);
43    }
44
45    build() {
46        Column() {
47            // 显示nodeContent管理器里存放的Native侧的组件
48            ContentSlot(this.nodeContent)
49        }
50    }
51}
52```
53