You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
1.6 KiB

2 years ago
# BI.config都可以做哪些事情,有哪些应用场景?
1. 修改组件的props
```
// 本示例修改了组件的type属性,也是常用的一种场景,讲一个组件替换为另外一个
BI.config("bi.button", props => {
props.type = "my.button";
return props;
});
```
2. 修改组件的默认props
```
// 本示例修改了bi.button的默认属性,配置方法是在组件的shortcut后面添加.props
BI.config("bi.button.props", props => {
props.minWidth = 100;
return props;
});
```
3. 修改常量资源
```
// 有如下常量资源
BI.constant("bi.constant.items", [
{
id: 1,
text: 1,
},
]);
// 通过config方法拓展常量资源
BI.config("bi.constant.items", items => {
items.push({
id: 2,
text: 2,
});
return items;
});
```
4. 修改provider
```
// 定义provider
var Provider = function () {
var items = [
{
id: 1,
text: 1,
},
];
this.inject = function (item) {
items.push(item);
};
this.$get = function () {
return BI.inherit(BI.OB, {
getItems: function () {
return items.slice(0);
},
});
};
};
BI.provider("bi.provider.demo", Provider);
// 配置provider,对外开放的拓展接口大多采用provider的形式. 这样有什么好处? 和直接配置constant有什么比优点吗
BI.config("bi.provider.demo", (provider) => {
provider.inject({
id: 2,
text: 2,
});
});
```
5. 配置一些系统级的配置
```
BI.config("bi.provider.system", (provider) => {
// Size相关,响应式,worker,模块依赖等
});
```