ConfigProvider 全局化配置

大约 2 分钟

ConfigProvider 全局化配置

为组件提供统一的全局化配置。

示例

基本用法

使用

ConfigProvider 使用 Vue 的 provide / injectopen in new window 特性,只需在应用外围包裹一次即可全局生效。

<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 个汉字之间的空格booleantrue
componentSize设置 antd 组件大小small | middle | large-3.0
csp设置 Content Security Policyopen in new window 配置-
direction设置文本展示方向。 示例ltr | rtlltr3.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() => window3.0
input设置 Input 组件的通用属性{ autocomplete?: string }-3.0
locale语言包配置,语言包可到 ant-design-vue/es/localeopen in new window 目录下寻找object-1.5.0
pageHeader统一设置 pageHeader 的 ghost,参考 pageHeader'true'1.5.0
prefixCls设置统一样式前缀。注意:需要配合 less 变量 @ant-prefix 使用stringant
renderEmpty自定义组件空状态。参考 空状态slot | Function(componentName: string): VNode-
space设置 Space 的 size,参考 Space{ size: small | middle | large | number }-3.0
transformCellTextTable 数据渲染前可以再次改变,一般用户空数据的默认配置Function({ text, column, record, index }) => any-1.5.4
virtual设置 false 时关闭虚拟滚动boolean-3.0

ConfigProvider.config() 3.0.0+

设置 ModalMessageNotification rootPrefixCls。

ConfigProvider.config({
  prefixCls: 'fs',
});

or

// 如下配置支持响应式数据,你可以通过 prefixCls.value = 'other' 直接改变
const prefixCls = ref('fs');
ConfigProvider.config({
  prefixCls,
});
上次编辑于:
贡献者: jiapeng.duan