2.6 KiB
		
	
	
	
	
			
		
		
	
	
			2.6 KiB
		
	
	
	
	
使用
ConfigProvider 使用 Vue 的 provide / inject 特性,只需在应用外围包裹一次即可全局生效。
<template>
  <a-config-provider :getPopupContainer="getPopupContainer">
    <app />
  </a-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 属性来进行配置:
<a-config-provider :csp="{ nonce: 'YourNonceCode' }">
  <a-button>My Button</a-button>
</a-config-provider>
API
| 参数 | 说明 | 类型 | 默认值 | 版本 | 
|---|---|---|---|---|
| autoInsertSpaceInButton | 设置为 false时,移除按钮中 2 个汉字之间的空格 | boolean | true | |
| csp | 设置 Content Security Policy 配置 | { nonce: string } | - | |
| renderEmpty | 自定义组件空状态。参考 空状态 | slot-scope | Function(componentName: string): VNode | - | |
| getPopupContainer | 弹出框(Select, Tooltip, Menu 等等)渲染父节点,默认渲染到 body 上。 | Function(triggerNode, dialogContext) | () => document.body | |
| locale | 语言包配置,语言包可到 ant-design-vue/es/locale 目录下寻找 | object | - | 1.5.0 | 
| pageHeader | 统一设置 pageHeader 的 ghost,参考 pageHeader | { ghost: boolean } | 'true' | 1.5.0 | 
| transformCellText | Table 数据渲染前可以再次改变,一般用户空数据的默认配置 | Function({ text, column, record, index }) => any | - | 1.5.4 | | 
FAQ
为什么我使用了 ConfigProvider locale,时间类组件的国际化还有问题?
请检查是否设置了 moment.locale('zh-cn'),或者是否有两个版本的 moment 共存。
配置 getPopupContainer 导致 Modal 报错?
当如下全局设置 getPopupContainer 为触发节点的 parentNode 时,由于 Modal 的用法不存在 triggerNode,这样会导致 triggerNode is undefined 的报错,需要增加一个判断条件。
 <ConfigProvider
-  getPopupContainer={triggerNode => triggerNode.parentNode}
+  getPopupContainer={node => {
+    if (node) {
+      return node.parentNode;
+    }
+    return document.body;
+  }}
 >
   <App />
 </ConfigProvider>