Config
App应用级别的配置类
说明
Config初始化的实例能配置整个App, 也能根据使用的平台单独配置而互不影响. 另外, 配置信息也能自定义, 比如说存放合成变量.
获取过一次的配置会被缓存在实例中, 便于后续快速使用. 此外, 在业务中可用过this.$config获取已定义的变量, 比如:
this.$config.get('mode') => 'ios/md'config的初始化Vimo安装的时候就搞定了, 实例会在window.VM.config中也留一份, 便于外部业务能访问到.
关于配置的优先级
也可以在url中传入配置参数, 通过url配置App的前后缀, 例如 http://xx.xx.com?vmMode=ios
则参数mode的值为ios, 改变mode并无法改变真实的mode环境, 因为平台验证有自己的isMatch方法, 切记!!
优先级
url获取配置信息(URL) > 用户自定义配置(Config) > 平台默认配置(Platform)
第一优先级(URL):
http://xx.xx.com?vmMode=ios
第二优先级(Config):
在src/config/app-configs.js中的platforms字段中设置
export default {
domain: '',
platforms: {
ios: {
mode: 'md'
}
}
}
第三优先级(Config):
在src/config/app-configs.js中根属性中设置
export default {
domain: '',
mode: 'ios'
}
第四优先级(Platform):
如果当前的_platforms = ['mobile','ios','wechat']
在src/config/platform-configs.js中设置
export default {
wechat: {
settings: {
mode: 'md'
}
}
}
第五优先级(Platform):
如果当前的_platforms = ['mobile','ios','wechat']
在src/config/platform-configs.js中设置
export default {
ios: {
settings: {
mode: 'md'
}
}
}可配置的参数有
| 参数 / params | 默认值 / IOS | 默认值 / Android | 描述 / Description |
|---|---|---|---|
| mode | ios | md | 模式 |
| hideNavBar | false | false | 是否隐藏navbar |
| toolbarMinHeight | 44 | 56 | toolbar的最小高度 |
| iconMode | ios | md | icon的模式 |
| menuType | reveal | overlay | menu展示方式 |
| backButtonText | '' | '' | 后退按钮文字 |
| backButtonIcon | '' | '' | 后退按钮图标icon |
| spinner | ios | crescent | 菊花图配型 |
| tabsHighlight | false | true | tab是否有下划线 |
| tabsPlacement | bottom | bottom | tab的放置位置 |
| pageTransition | ios-transition | zoom-transition | 转场动画 |
| showIndicatorWhenPageChange | true | true | 转场是否显示Indicator |
方法 / Methods
cache() → {object}
- 源码:
获取缓存配置
get(keyopt, fallbackValueopt) → {String}
- 源码:
获取配置信息
参数 / Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
key |
string |
<optional> |
查找的key |
|
fallbackValue |
any |
<optional> |
null
|
第二选择 |
getBoolean(keyopt, fallbackValueopt) → {Boolean}
- 源码:
和get()方法类似, 不过只返回boolean类型, 比如"true"返回true
参数 / Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
key |
string |
<optional> |
key值 |
|
fallbackValue |
boolean |
<optional> |
false
|
备选值 |
getNumber(keyopt, fallbackValueopt) → {Number}
- 源码:
和get()方法类似, 不过只返回number类型
参数 / Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
key |
string |
<optional> |
key值 |
fallbackValue |
number |
<optional> |
备选值 |
set(platformopt, keyopt, valueopt) → {this}
- 源码:
修改config中定义的键值对, 可针对平台单独设置.
示例 / Example
set('key', 'value') = set key/value pair
set('ios', 'key', 'value') = set key/value pair for platform
参数 / Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
platform |
string |
<optional> |
平台类型, 可以是(either 'ios' or 'android'). 如果不填将对所有平台生效. |
key |
string |
<optional> |
key值 |
value |
string |
<optional> |
设置的值 |
settings(arg0, arg1)
- 源码:
全部重新设置
- 如果不传入参数则为获取_s的数据,
- 如果传递
settings({...}), 则设置_s的值, 同时清空_c - 如果传递
settings('ios', {...}), 则清除_s.platforms['ios']下的值并设置新值, 同时清空_c
示例 / Example
settings()
settings({...})
settings('ios', {...})
参数 / Parameters:
| Name | Type | Description |
|---|---|---|
arg0 |
* | 参数0 |
arg1 |
* | 参数1 |