The UniApp applet supports plug-in subcontracting. After subcontracting, the plug-in can be independently released and updated. The steps to obtain the subcontracted plug-in include: referencing the subcontracted plug-in in the main package manifest.json; using the is attribute in the page to use the subcontracted plug-in; obtaining the subcontracted plug-in instance through getPluginManager().getPlugin(pluginId); the subcontracted plug-in is not When loading, you can pass in a callback function to obtain the instance asynchronously.
How to obtain the UniApp applet plug-in after subcontracting
The UniApp applet supports plug-in subcontracting. After subcontracting Plugins can be released and updated independently of the main package. To obtain the plug-in in the sub-package, you can follow the following steps:
1. Reference the sub-package plug-in in the main package
In themanifest of the main package Add a reference to the subpackaging plug-in in the .json
file, for example:
{ "usingComponents": { "my-plugin": "../packages/my-plugin/index" } }
2. Use the subpackaging plug-in in the page
In the page, you can pass Theis
attribute inuses a subcontracting plug-in, for example:
3. Get the subcontracting plug-in instance through the plug-in ID
If you need to get the subcontracted plug-in instance in JavaScript code, you can use thegetPluginManager().getPlugin(pluginId)
method, wherepluginId
is the subcontracted plug-inmanifest.json
The ID specified in the file, for example:
const pluginManager = getPluginManager(); const pluginInstance = pluginManager.getPlugin('plugin-from-subpackage');
4. Asynchronously obtain the subcontracting plug-in instance
If the subcontracting plug-in has not been loaded,getPlugin(pluginId)
method will returnnull
. At this point, you can pass in a callback function to be executed after the subpackaged plug-in is loaded:
pluginManager.getPlugin('plugin-from-subpackage', (pluginInstance) => { // 分包插件已加载完成 });
By following these steps, you can easily obtain the subpackaged plug-in in the UniApp applet.
The above is the detailed content of How to obtain the uniapp applet plug-in after subcontracting. For more information, please follow other related articles on the PHP Chinese website!