Home >Web Front-end >uni-app >How to obtain the uniapp applet plug-in after subcontracting

How to obtain the uniapp applet plug-in after subcontracting

下次还敢
下次还敢Original
2024-04-06 03:51:211303browse

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

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 the manifest of the main package Add a reference to the subpackaging plug-in in the .json file, for example:

<code class="json">{
  "usingComponents": {
    "my-plugin": "../packages/my-plugin/index"
  }
}</code>

2. Use the subpackaging plug-in in the page

In the page, you can pass The is attribute in <template> uses a subcontracting plug-in, for example:

<code class="vue"><template>
  <my-plugin is="plugin-from-subpackage"></my-plugin>
</template></code>

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 the getPluginManager().getPlugin(pluginId) method, where pluginId is the subcontracted plug-in manifest.json The ID specified in the file, for example:

<code class="js">const pluginManager = getPluginManager();
const pluginInstance = pluginManager.getPlugin('plugin-from-subpackage');</code>

4. Asynchronously obtain the subcontracting plug-in instance

If the subcontracting plug-in has not been loaded, getPlugin(pluginId) method will return null. At this point, you can pass in a callback function to be executed after the subpackaged plug-in is loaded:

<code class="js">pluginManager.getPlugin('plugin-from-subpackage', (pluginInstance) => {
  // 分包插件已加载完成
});</code>

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to subcontract uniappNext article:How to subcontract uniapp