每个 Light视图的this上下文中都有一个相互独立的 $page 变量,不过它在不同视图中是隔离而且只读的。
this.$page.config.env
有时候为了兼容性或者为了增强某个端上的能力,需要编写平台特异的代码。 light 提供了 this.$page.config.env来获取当前执行环境的信息。
环境变量中的字段:
| 字段名 | 类型 | 描述 | 
|---|---|---|
| platform | String | Current running platform, could be “Android”, “iOS” or “Web”. | 
| weexVersion | String | The version of Weex SDK. | 
| appName | String | Mobile app name or browser name. | 
| appVersion | String | The version of current app. | 
| osName | String | The OS name, could be “Android” or “iOS”. | 
| osVersion | String | The version of current OS. | 
| deviceModel | String | Mobile phone device model. (native only) | 
| deviceWidth | Number | Screen resolution width. | 
| deviceHeight | Number | Screen resolution height. | 
Light.requireModule
对于那些不依赖 UI 交互的原生功能,jsn 将其封装成模块,这是一种通过 javascript 调用原生能力的方法。除了内置模块以外,将已有的原生模块移植到 JSNative 平台也很方便。你可以使用 light.requireModule 接口引用自定义的或者内置的模块。
| Light.requireModule(name: string): Object | void; | 
参数:
- 大小写敏感的模块名。
返回值:
- 如果模块已经注册了,返回一个 Proxy对象(如果环境不支持Proxy则返回一个普通对象),可以使用这个对象调用客户端注册的方法。
- 如果模块未注册,返回 undefined。
使用原生模块
你可以像使用不同 javascript 函数一样使用原生注册的接口。
| <template> |