使用小程序插件

引入插件代码包

app.config.js 中声明需要使用的插件:

module.exports = {
  plugins: {
    myPlugin: {
      version: '1.0.0',
      provider: 'wxidxxxxxxxxxxxxxxxx',
    },
  },
};

使用插件

自定义组件

使用插件的自定义组件不需要申明 usingComponents,而是使用 Rsmax 的 requirePluginComponent 方法。

import { requirePluginComponent } from 'rsmax/macro';

const Hello = requirePluginComponent('plugin://myPlugin/hello-component');

export default ()  => (
  <View>
    <Hello name="Rsmax">
  </View>
)

页面

需要跳转到插件页面时,url 使用 plugin:// 前缀,形如 plugin://PLUGIN_NAME/PLUGIN_PAGE, 如:

<Navigator url="plugin://myPlugin/hello-page">Go to pages/hello-page!</Navigator>

JavaScript 接口

import { requirePlugin } from 'rsmax/macro';

const myPlugin = requirePlugin('myPlugin');

myPlugin.hello();

const world = myPlugin.world;