codecamp

小程序插件

引入插件代码包

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

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

使用插件

自定义组件

使用插件的自定义组件同样不需要申明 usingComponents,你可以直接对组件提供的自定义组件进行引用:

import Hello from 'plugin://myPlugin/hello-component';
export default () => (
<View>
<Hello name="Remax">
</View>
)

页面

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

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

JavaScript 接口

const myPlugin = requirePlugin('myPlugin');
myPlugin.helloApi();
const word = myPlugin.world;
事件
小程序自定义组件
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

跨平台开发

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }