$getConfig()
获取当前全局环境变量和配置信息。
Returns:
- config (object): 配置对象;
- bundleUrl (string): bundle 的 url;
- debug (boolean): 是否是调试模式;
- env (object): 环境对象;
- weexVersion (string): Weex sdk 版本;
- appName (string): 应用名字;
- appVersion (string): 应用版本;
- platform (string): 平台信息,是 iOS、Android 还是 Web;
- osVersion (string): 系统版本;
- deviceModel (string): 设备型号 (仅原生应用);
- deviceWidth (number): 设备宽度,默认为 750,满屏是750;
- deviceHeight (number): 设备高度。
具体使用
在元素标签中使用:
<template>
<div class='flex' style='position: fixed; bottom: 0; width: {{$getConfig().env.deviceWidth}}px;'>
<div class='flex-item'>
<text>2</text>
</div>
<div class='flex-item'>
<text>2</text>
</div>
<div class='flex-item'>
<text>2</text>
</div>
</div>
</template>
在组件的方法中通过 this (Vm)上下文访问这些 API:
<script>
module.exports = {
methods: {
somemethod: function() {
this.$getConfig().env.deviceWidth;
}
}
}
</script>