1# @ohos.pluginComponent (PluginComponentManager)(系统接口) 2 3用于给插件组件的使用者请求组件与数据,使用者发送组件模板和数据。如需实现插件模板的显示,请参考[PluginComponent](arkui-ts/ts-basic-components-plugincomponent-sys.md)。 4 5> **说明:** 6> 7> - 本模块首批接口从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 8> 9> - 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.pluginComponent (PluginComponentManager)](js-apis-plugincomponent.md)。 10 11## 导入模块 12 13```ts 14import { pluginComponentManager } from '@kit.ArkUI' 15``` 16 17### PushParameterForStage 18 19用于设置Stage模型下使用PluginManager.Push方法时候的需要传递的参数。 20 21**模型约束:** 此接口仅适用于Stage模型。 22 23**系统接口:** 此接口为系统接口。 24 25**系统能力:** SystemCapability.ArkUI.ArkUI.Full 26 27| 名称 | 类型 | 必填 | 说明 | 28| --------- | ----------------------------------- | ---- | ---------------------------------------- | 29| owner | [Want](../apis-ability-kit/js-apis-application-want.md) | 是 | 组件提供方Ability信息。 | 30| target | [Want](../apis-ability-kit/js-apis-application-want.md) | 是 | 组件使用者Ability信息。 | 31| name | string | 是 | 组件名称。 | 32| data | [KVObject](js-apis-plugincomponent.md#kvobject) | 是 | 组件数据值。 | 33| extraData | [KVObject](js-apis-plugincomponent.md#kvobject) | 是 | 附加数据值。 | 34| jsonPath | string | 否 | 存放模板路径的[external.json](#externaljson文件说明)文件的路径。 | 35 36### RequestParameterForStage 37 38用于设置Stage模型下使用PluginManager.Request方法时候的需要传递的参数。 39 40**系统接口:** 此接口为系统接口。 41 42**模型约束:** 此接口仅适用于Stage模型。 43 44**系统能力:** SystemCapability.ArkUI.ArkUI.Full 45 46| 名称 | 类型 | 必填 | 说明 | 47| -------- | ----------------------------------- | ---- | ---------------------------------------- | 48| owner | [Want](../apis-ability-kit/js-apis-application-want.md) | 是 | 组件使用者Ability信息。 | 49| target | [Want](../apis-ability-kit/js-apis-application-want.md) | 是 | 组件提供者Ability信息。 | 50| name | string | 是 | 请求组件名称。 | 51| data | [KVObject](js-apis-plugincomponent.md#kvobject) | 是 | 附加数据。 | 52| jsonPath | string | 否 | 存放模板路径的[external.json](#externaljson文件说明)文件的路径。jsonPath字段不为空或者未设置的时候不触发Request通信。 | 53 54### push 55 56push(param: PushParameterForStage, callback: AsyncCallback<void>): void 57 58组件提供者向组件使用者主动发送组件与数据。 59 60**系统接口:** 此接口为系统接口。 61 62**模型约束:** 此接口仅适用于Stage模型。 63 64**参数:** 65| 参数名 | 类型 | 必填 | 说明 | 66| -------- | ---------------------------------------- | ---- | ------------ | 67| param | [PushParameterForStage](#pushparameterforstage) | 是 | 组件使用者的详细信息。 | 68| callback | AsyncCallback<void> | 是 | 此次接口调用的异步回调。 | 69 70**示例:** 71 72```ts 73import { pluginComponentManager } from '@kit.ArkUI' 74pluginComponentManager.push( 75 { 76 owner: { 77 bundleName: "com.example.provider", 78 abilityName: "com.example.provider.MainAbility" 79 }, 80 target: { 81 bundleName: "com.example.provider", 82 abilityName: "com.example.provider.MainAbility", 83 }, 84 name: "ets/pages/plugin2.js", 85 data: { 86 "js": "ets/pages/plugin.js", 87 "key_1": 1111, 88 }, 89 extraData: { 90 "extra_str": "this is push event" 91 }, 92 jsonPath: "", 93 }, 94 (err, data) => { 95 console.log("push_callback:err: ", JSON.stringify(err)); 96 console.log("push_callback:data: ", JSON.stringify(data)); 97 console.log("push_callback: push ok!"); 98 } 99) 100``` 101 102### request 103 104request(param: RequestParameterForStage, callback: AsyncCallback<RequestCallbackParameters>): void 105 106组件使用者向组件提供者主动请求组件。 107 108**系统接口:** 此接口为系统接口。 109 110**模型约束:** 此接口仅适用于Stage模型。 111 112**参数:** 113 114| 参数名 | 类型 | 必填 | 说明 | 115| -------- | ---------------------------------------- | ---- | ----------------------------------- | 116| param | [RequestParameterForStage](js-apis-plugincomponent.md#requestcallbackparameters) | 是 | 组件模板的详细请求信息。 | 117| callback | AsyncCallback<[RequestCallbackParameters](js-apis-plugincomponent.md#requestcallbackparameters) \| void> | 是 | 此次请求的异步回调, 通过回调接口的参数返回接受请求的数据。 | 118 119**示例:** 120 121```ts 122import { pluginComponentManager } from '@kit.ArkUI' 123pluginComponentManager.request( 124 { 125 owner: { 126 bundleName: "com.example.provider", 127 abilityName: "com.example.provider.MainAbility" 128 }, 129 target: { 130 bundleName: "com.example.provider", 131 abilityName: "ets/pages/plugin2.js", 132 }, 133 name: "plugintemplate", 134 data: { 135 "key_1": " myapplication plugin component test", 136 }, 137 jsonPath: "", 138 }, 139 (err, data) => { 140 console.log("request_callback: componentTemplate.ability=" + data.componentTemplate.ability) 141 console.log("request_callback: componentTemplate.source=" + data.componentTemplate.source) 142 } 143) 144``` 145 146## external.json文件说明 147 148external.json文件由开发者创建。external.json中以键值对形式存放组件名称以及对应模板路径。以组件名称name作为关键字,对应模板路径作为值。 149 150**示例** 151 152```json 153{ 154 "PluginProviderExample": "ets/pages/PluginProviderExample.js", 155 "plugintemplate2": "ets/pages/plugintemplate2.js" 156} 157 158```