ConfigProvider 全局化配置
大约 2 分钟
ConfigProvider 全局化配置
为组件提供统一的全局化配置。
示例
基本用法
使用
ConfigProvider 使用 Vue 的 provide / inject 特性,只需在应用外围包裹一次即可全局生效。
<template>
<f-config-provider :getPopupContainer="getPopupContainer">
<!-- <app /> -->
</f-config-provider>
</template>
<script>
export default {
methods: {
getPopupContainer(el, dialogContext) {
if (dialogContext) {
return dialogContext.getDialogWrap();
} else {
return document.body;
}
},
},
};
</script>
Content Security Policy
部分组件为了支持波纹效果,使用了动态样式。如果开启了 Content Security Policy (CSP),你可以通过 csp 属性来进行配置:
<f-config-provider :csp="{ nonce: 'YourNonceCode' }">
<f-button>My Button</f-button>
</f-config-provider>
API
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| autoInsertSpaceInButton | 设置为 false 时,移除按钮中 2 个汉字之间的空格 | boolean | true | |
| componentSize | 设置 antd 组件大小 | small | middle | large | - | 3.0 |
| csp | 设置 Content Security Policy 配置 | - | ||
| direction | 设置文本展示方向。 示例 | ltr | rtl | ltr | 3.0 |
| dropdownMatchSelectWidth | 下拉菜单和选择器同宽。默认将设置 min-width,当值小于选择框宽度时会被忽略。false 时会关闭虚拟滚动 | boolean | number | - | |
| form | 设置 Form 组件的通用属性 | { validateMessages?: ValidateMessages, requiredMark?: boolean | optional, colon?: boolean} | - | 3.0 |
| getPopupContainer | 弹出框(Select, Tooltip, Menu 等等)渲染父节点,默认渲染到 body 上。 | Function(triggerNode, dialogContext) | () => document.body | |
| getTargetContainer | 配置 Affix、Anchor 滚动监听容器。 | () => HTMLElement | () => window | 3.0 |
| input | 设置 Input 组件的通用属性 | { autocomplete?: string } | - | 3.0 |
| locale | 语言包配置,语言包可到 ant-design-vue/es/locale 目录下寻找 | object | - | 1.5.0 |
| pageHeader | 统一设置 pageHeader 的 ghost,参考 pageHeader | 'true' | 1.5.0 | |
| prefixCls | 设置统一样式前缀。注意:需要配合 less 变量 @ant-prefix 使用 | string | ant | |
| renderEmpty | 自定义组件空状态。参考 空状态 | slot | Function(componentName: string): VNode | - | |
| space | 设置 Space 的 size,参考 Space | { size: small | middle | large | number } | - | 3.0 |
| transformCellText | Table 数据渲染前可以再次改变,一般用户空数据的默认配置 | Function({ text, column, record, index }) => any | - | 1.5.4 |
| virtual | 设置 false 时关闭虚拟滚动 | boolean | - | 3.0 |
ConfigProvider.config() 3.0.0+
设置 Modal、Message、Notification rootPrefixCls。
ConfigProvider.config({
prefixCls: 'fs',
});
or
// 如下配置支持响应式数据,你可以通过 prefixCls.value = 'other' 直接改变
const prefixCls = ref('fs');
ConfigProvider.config({
prefixCls,
});