@TOC
一、app.json配置属性之plugins
1.添加插件
首先打开官网网址:mp.weixin.qq.com/wxamp/basic…
在微信公众平台后台,登录,设置-第三方服务-添加插件。
选择一个程序后点击添加就行
2.配置插件
在app.json中添加插件
{
"pages": [
"pages/weather/weather",
"pages/calendar/calendar",
"pages/index/index",
"pages/map/map"
],
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序位置展示"
}
},
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "LBS定位插件",
"navigationBarTextStyle": "black"
},
"style": "v2",
"sitemapLocation": "sitemap.json",
"plugins": {
"myPlugin": {
"version": "1.1.2",
"provider": "wx8b974282f75dcd3e"
}
}
}
3.使用插件
3.1 本地使用
json
{
"usingComponents": {
"hello-component": "plugin://myPlugin/hello-component"
}
}
wxml
<hello-component/>
js
使用插件的 js 接口时,可以使用 requirePlugin 方法。例如,插件提供一个名为 hello 的方法和一个名为 world 的变量,则可以像下面这样调用:
var myPluginInterface = requirePlugin('myPlugin');//获取组件
myPluginInterface.hello();//调用组件方法
var myWorld = myPluginInterface.world;//获取组件属性
3.2 跳转插件页面
插件页面时配置号插件就有的,非插件开发者无法编辑和修改,需要跳转到插件页面时,url 使用 plugin:// 前缀,如:
<navigator url="plugin://myPlugin/hello-page">
Go to pages/hello-page!
</navigator>