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